Nginx + PHP的FASTCGI失败 – 如何debugging?

我有一个运行Nginx + PHP的AMAZON EC2服务器,通过端口9000与PHP FASTCGI。

服务器运行良好几分钟,过了一会儿(在这种情况下有几千次命中)FastCGI Dies和Nginx返回502错误。

Nginx日志显示

2010/01/12 16:49:24 [error] 1093#0: *9965 connect() failed (111: Connection refused) while connecting to upstream, client: 79.180.27.241, server: localhost, request: "GET /data.php?data=7781 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "site1.mysite.com", referrer: "http://www.othersite.com/subc.asp?t=10" 

我怎样才能debugging是什么造成FastCGI死亡?

我意识到OP现在可能已经开始了,但是如果有人来到这里也遇到同样的问题,我希望这会有所帮助。


在默认设置下,NGINX以用户“nobody”运行,而spawn-fcgi以用户“root”产生php-cgi子目录。 所以,NGINX无法连接到具有当前权限的fastcgi://127.0.0.1:9000。 你所要做的只是改变一下spawn-fcgi命令来解决这个问题。

 spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php-cgi -C 5 -U nobody 

或者你可以使用UNIX套接字(我更喜欢这种方法)

 spawn-fcgi -s /var/run/fcgi.sock -f /usr/bin/php-cgi -C 5 -U nobody 

然后把nginx.conf中的fastcgi_pass改为:

 ... location ~ \.php$ { fastcgi_pass unix:/var/run/fcgi.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_$ } ... 

你可以开始检查什么PHP打印标准错误,当它死亡。 如果没有说明这个问题,那么可以启发一下PHP的过程,看看他们做了些什么,然后看看最后的事情。 在一个合适的stream程监控框架(如daemontools )下运行FCGIstream程也是一个好主意 – 这就是我如何在nginx下运行我所有的PHP进程。