The use case you mention is very common, and it's detailed in the common Nginx pitfalls page under the section Front Controller Pattern Web Apps
As per the aforementioned page, for Drupal, Joomla, etc., just use this inside your location block:
try_files $uri $uri/ /index.php?q=$uri&$args;
Since you want to use the "page" variable name, your code will look as follows:
location / {
try_files $uri $uri/ /index.php?page=$uri&args;
}
The part $uri/
is relevant only if you want to serve content from directories, for example if you want to serve a Wordpress blog from yourdomain.com/blog/
. If that's not the case, you can remove the $uri/
part.
My advice is to not use page
as the variable to pass the section/route to PHP, because you might end up having a confusion between which section of the website to show vs. which page number. Page is misleading, I'd use route instead.
Of course, your mileage may vary and you may require something more complex based on your needs, but for basic sites, these will work perfectly. You should always start simple and build from there.
Additionally, to make debugging easier, consider using a verbose error log setting, I'd use info
or notice
to debug routing:
error_log logs/error.log info;
Good luck and keep us posted on how you solved the issue.