502 bad gateway error with php5-fpm on Debian 7

Francis Daly francis at daoine.org
Wed Feb 20 23:13:10 UTC 2013

On Wed, Feb 20, 2013 at 11:54:08PM +0100, GASPARD Kévin wrote:
> >On Wed, Feb 20, 2013 at 11:27:04PM +0100, GASPARD Kévin wrote:

> >So your fastcgi server is expected to be at /var/run/php5-fpm.sock.
> >
> >  ls -l /var/run/php5-fpm.sock
> srw-rw-rw- 1 root root 0 Feb 20 14:08 /var/run/php5-fpm.sock
> >
> >should show you that it really is there.
> I forget to say, but yes it's here and I've runned the daemon php-fpm.

That's fine - the fastcgi server is listening on the unix socket.

> >>#                fastcgi_pass;
> >>		fastcgi_pass unix:/var/run/php5-fpm.sock;
> >
> >This looks like it *used to* try to access, but now it
> >accesses the expected socket.
> Yeah, also forget to say that but this configuration was first used on  
> CentOS 6 and it worked well.

That's also fine.

The issue is that the nginx that you are testing is *not* trying to
access the unix socket -- it is instead trying to access to network port.

So either this is not the running config; or this is not the server{}
block used in your test request.

> >>2013/02/20 23:19:25 [error] 17211#0: *207 connect() failed (111:
> >>Connection refused) while connecting to upstream, client:  
> >>,
> >>server: subdomain.koshie.fr, request: "GET /wp-admin/info.php HTTP/1.1",
> >>upstream: "fastcgi://", host: "blog.koshie.fr"
> >
> >This says it *actually* tried to access, and failed.
> Seems logical because I ask to use /var/run/php5-fpm.sock instead of the  
> commented value in /etc/nginx/nginx.conf, right?

You want nginx to access the unix socket. It is trying to access the
network port.

> >The nginx config you showed is not the one that the running nginx is
> >using when it created this log file.
> I've pasted a working vhost configuration file and pasted an error on an  
> other configuration file but they are identical except for document root  
> and domain. To create this file I've used 'cp' and modified it.

When a request comes in to nginx, it chooses exactly one server{} block
to handle it. That server{} block is chosen based firstly on the incoming
ip:port; and then secondly on the incoming host name used in the request.

Looking at your config file, plus every file include'd in it, can you
see which one server{} block is used for this request? (You'll need
to look at all of the "listen" directives first, and then all of the
"server_name" directives in the server{}s with the "listen" that best
matches the incoming ip:port.)

What fastcgi_pass line is used in that one server{} block?

> nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
> nginx: configuration file /etc/nginx/nginx.conf test is successful
> And no output for 'nginx -s reload'.

Because of that, I guess that the problem is in identifying the correct

Francis Daly        francis at daoine.org

More information about the nginx mailing list