Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's part of config in the server block:

I was unable to execute any php script , I placed a file named test.php under /var/html , but when I point to http://localhost/test.php , I got a result:

File not found.,

That's not generated by nginx , since it's different from the 404 page of nginx.

location / {
    root   /var/html;
    index  index.html index.htm;
}

    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php; 
        fastcgi_intercept_errors on;
        fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        include        fastcgi.conf;
    }

Did I miss anything ?

share|improve this question
up vote 4 down vote accepted

You're defining the document root under the / location, and this doesn't apply to the \.php$ location. Move the root directive outside the / location so that it is applied to both.

root   /var/html;
location / {
    index  index.html index.htm;
}
location ~ \.php$ {
    ...
}
share|improve this answer
1  
Root inside locations is bad, by the way. (Relevant to question, not the answer). – Dmitry Verkhoturov May 22 '12 at 12:13
    
@DmitryVerkhoturov and mgorven Thanks to both of you defining one root in nginx conf resolved my error. I was searching it for 2 days ..... THANKS – Haider Ali Sep 7 '15 at 12:10

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.