Nginx 1.0.3 with php-fpm, php report 404 error

Hi everyone

I am using nginx 1.0.3 under CentOS 5.6, with php-fpm.

nginx works fine with static file, such as html,txt. But not with php
file.

I wrote a phpinfo.php file in my webserver, my browser and nginx log
both
report an 404 error.

I changed nothing but only add below in my nginx.conf file:

*location ~ .php$ {

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi.conf;
}*

this is fastcgi.conf:
*
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

PHP only, required if PHP was built with --enable-force-cgi-redirect

#fastcgi_param REDIRECT_STATUS 200;*

and php-fm works fine:
*[root@cacti database]# more /data/logs/php-fpm.log
[27-May-2011 10:04:51] NOTICE: configuration file
/usr/local/php/etc/php-fpm.conf test is successful

[27-May-2011 10:07:14] NOTICE: using inherited socket fd=6,
“127.0.0.1:9000”
[27-May-2011 10:07:14] NOTICE: fpm is running, pid 25610
[27-May-2011 10:07:14] NOTICE: ready to handle connections*

and this is nginx access log:

172.17.188.133 - - [27/May/2011:10:46:37 +0800] “GET /info.php
HTTP/1.1”
404 5 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101
Firefox/4.0.
1”

so, what is the problely problem of this 404 error?

thanks!

On Fri, May 27, 2011 at 10:26 AM, baalchina [email protected] wrote:

Hi everyone

I am using nginx 1.0.3 under CentOS 5.6, with php-fpm.

nginx works fine with static file, such as html,txt. But not with php file.

I wrote a phpinfo.php file in my webserver, my browser and nginx log both
report an 404 error.

did you set root parameter in location block (eg. location / { … })
or in server block (server { … })? You must set it in server block
if you want the location php to use the root or else it’ll use default
root. Checking error log could also show you where nginx tried to find
the file.

location ~ .php$ should be a part of location /
Or else, nginx cannot determine $document_root

2011-5-2711:26 baalchina д

thanks!

I moved location ~.php to location ,works fine now.

2011/5/27 [email protected]