0

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 ?

daisy
  • 747
  • 4
  • 14
  • 30

1 Answers1

5

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$ {
    ...
}
mgorven
  • 30,615
  • 7
  • 79
  • 122
  • 1
    [Root inside locations](http://wiki.nginx.org/Pitfalls#Root_inside_Location_Block) 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 07 '15 at 12:10