Why doesn't nginx like my $args?

Jonathan asked:

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)

My answer:


Because you forgot the ? between index.php and $args.

try_files $uri $uri/ /blog/index.php?$args;

Of course, with WordPress you do not need to use $args at all.

try_files $uri $uri/ /blog/index.php;

is sufficient.

Update :

It appears you are using try_files with alias directive. That’s a long standing bug in nginx, use root directive instead.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.