Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a server on AMAZON EC2 running Nginx +PHP with PHP FASTCGI via port 9000.

The server runs fine for a few minutes and after a while (several thousands of hits in this case) FastCGI Dies and Nginx returns 502 Error.

Nginx log shows

 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"

How can I debug what is causing FastCGI to die?

share|improve this question
    
What cgi manager do you have? (i.e. php-fpm / spawn-fcgi). What number of php-fastcgi process do you have? What is your OS somaxcon value and php process backlog size? –  SaveTheRbtz Jan 13 '10 at 0:45

2 Answers 2

I realize that the OP may have moved on by now, but if somebody came here with the same problem, I hope this helps.


In a default setup, NGINX runs as the user "nobody" whereas spawn-fcgi spawns php-cgi children as the user "root". So, NGINX is unable to connect to fastcgi://127.0.0.1:9000 with it's current permissions. All you have to do is change the spawn-fcgi command a little bit to fix this.

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

Or you could use a UNIX socket (I prefer this method)

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

And change your fastcgi_pass in nginx.conf to this:

...
 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_$
    }
...
share|improve this answer

You can start by examining what PHP prints on standard error when it dies. If that sheds no light on the matter, then it might be enlightening to hook up a strace to the PHP processes and watch them do their thing, and then look at the last things it does. Running your FCGI processes under a competent process monitoring framework such as daemontools is also a good idea -- it's how I run all my PHP processes under nginx.

share|improve this answer

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.