Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:, server: localhost, request: "GET /data.php?data=7781 HTTP/1.1", upstream: "fastcgi://", host: "", referrer: ""

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

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:// 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 -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
thanks @user46311 it's works for me – user244782 Sep 25 '14 at 11:57
there is no need for nginx and spawn-fcgi to run under the same user if they connect through a TCP socket. That's only required if you use a unix socket. – Luca G. Apr 6 at 9:18

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


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.