# Nginx 1.0.3 with php-fpm, php report 404 error

**URL:** <https://www.ruby-forum.com/t/nginx-1-0-3-with-php-fpm-php-report-404-error/207505>\
**Category:** NGINX\
**Created:** [May 27, 2011, 5:27am UTC](https://www.ruby-forum.com/t/nginx-1-0-3-with-php-fpm-php-report-404-error/207505 "2011-05-27T05:27:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 27, 2011, 5:27am UTC](https://www.ruby-forum.com/t/nginx-1-0-3-with-php-fpm-php-report-404-error/207505/1 "2011-05-27T05:27:10Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![baalchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ec9cab/32.png) [@baalchina](https://www.ruby-forum.com/u/baalchina)\
**Post date:** [May 27, 2011, 5:43am UTC](https://www.ruby-forum.com/t/nginx-1-0-3-with-php-fpm-php-report-404-error/207505/2 "2011-05-27T05:43:57Z")

</div>

On Fri, May 27, 2011 at 10:26 AM, baalchina [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![baalchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ec9cab/32.png) [@baalchina](https://www.ruby-forum.com/u/baalchina)\
**Post date:** [May 27, 2011, 5:55am UTC](https://www.ruby-forum.com/t/nginx-1-0-3-with-php-fpm-php-report-404-error/207505/3 "2011-05-27T05:55:50Z")

</div>

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

2011-5-2711:26 baalchina д

---

<div class="post-metadata">

**Author:** ![baalchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ec9cab/32.png) [@baalchina](https://www.ruby-forum.com/u/baalchina)\
**Post date:** [May 27, 2011, 6:12am UTC](https://www.ruby-forum.com/t/nginx-1-0-3-with-php-fpm-php-report-404-error/207505/4 "2011-05-27T06:12:31Z")

</div>

thanks!

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

2011/5/27 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
