Double try_files to solve the nginx's "No input file specified" issue

Howard asked:

I am following the nginx’s wiki (http://wiki.nginx.org/WordPress) to setup my wordpress

   location / {
                try_files $uri $uri/ /index.php?$args;
        }

By using the above lines, when a static file which is not found it will redirect to index.php of wordpress, that is okay but..

Problem: When I request an non-existence php script, e.g. http://www.example.com/foo.php, nginx will give me

No input file specified

I want nginx to return 404 instead of the above message, so in the main fcgi config, I add the 2nd try_files

location ~ .php$ {
    try_files  $uri =404;

    fastcgi_split_path_info ^(.+.php)(/.+)$;
    include /etc/nginx/fastcgi_params;
    ...
}

And this worked, but I am looking if there are any better way to handle it?

My answer:


Nope, that’s the normal way to handle it.


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.