On my ubuntu 12.10 server I upgraded php to 5.5. After getting 502 errors on my wordpress site I did some googling and discovered I need to change my nginx configs to match the passing of php scripts to php5-fpm.sock rather than port 9000. So I changed my site's config file to the below:

 # Pass PHP scripts on to PHP-FPM
    location ~* \.php$ {
        try_files       $uri /index.php;
        fastcgi_index   index.php;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;

I then did service nginx restart. But the 502 error persists.

Upon checking the error log I get:

2014/03/30 14:16:37 [error] 1451#0: *21 connect() failed (111: Connection refused) while connecting to upstream, client:,, server: www.harryg.me, request: "GET / HTTP/1.1", upstream: "fastcgi://", host: "harryg.me"

So it looks like php-fpm is trying to pass stuff to fastcgi:// Why isn't it obeying the config file change?


My /etc/php5/fpm/pool.d/www.conf has listen = /var/run/php5-fpm.sock in it.


I had this problem too, and I solved it by using TCP connections. Quoting this answer Error 502 in nginx + php5-fpm (found following the link from danmash):

The issue is socket itself, its problems on high-load cases is well-known. Please consider using TCP\IP connection instead of unix socket, for that you need to make these changes:

  • in php-fpm pool configuration replace listen = /var/run/php5-fpm.sock with listen =
  • in /etc/nginx/php_location replace fastcgi_pass unix:/var/run/php5-fpm.sock; with fastcgi_pass;

In your case it would be


Nginx error 502 represents that proxy is down or not returned any data or valid data. Make sure without nginx or proxy code itself is working fine. For details explanation check nginx and php log on request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.