I have a WordPress site located at mysite.com/blog
, the files of which are located in /var/www/mysite/wordpress
. Why, when I visit mysite.com/blog/test
, does my nested location block only get hit if I remove $args
from try_files
?
server {
server_name mysite.com;
location /blog {
alias /var/www/mysite/wordpress;
try_files $uri $uri/ /blog/index.php$args;
location ~ \.php {
# This is only reached if I remove $args from try_files
return 401; # For testing purposes
}
}
}
Here is the associated error in the log:
"/usr/share/nginx/html/index.php" failed (2: No such file or directory)
Because you forgot the
?
betweenindex.php
and$args
. The convenience variable$is_args
contains a?
when necessary, and is empty when there was no query string.Of course, with WordPress you do not need to use
$args
at all, as it gets the query string elsewhere:is sufficient.
It appears you are using
try_files
withalias
directive. That's a long standing bug in nginx, useroot
directive instead.