Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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

share|improve this answer

Using try_files in your PHP location only works so long as the server with that specific nginx instance also has the PHP code. This is certainly not always the case and therefore will not always work.

What you can do is use fastcgi_intercept_errors to have nginx intercept errors from your PHP backend and then process them with its own error_page error handler. This allows you a custom handler defined in nginx.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.