Today I upgraded my localhost server from nginx 1.6.3 to 1.8.0 and now all my local websites are getting a 502 bad gateway.

A standard nginx config file is as follows

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4

    server_name  yii2.dive;
    root        /media/Development/www/yii2/web;
    index       index.php;

    access_log  /media/Development/www/yii2/log/access.log combined;
    error_log   /media/Development/www/yii2/log/error.log warn;

    location / {
        try_files $uri $uri/ /index.php?$args;

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        try_files $uri =404;

    location ~ /\.(ht|svn|git) {
        deny all;

The error message I'm getting is as follows

2015/05/12 14:09:21 [error] 9295#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client:, server: yii2.dive, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "yii2.dive"

The socket at /var/run/php5-fpm.sock exists so there is no problem there.

I found someone else with a problem on the same upgrade but their issue is different to mine and not getting any errors.

I tried adding this line to /etc/nginx/fastcgi_params but it does not alleviate the problem.

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

Alternatively is there a way to downgrade back to 1.6.2 or 1.6.3 and I can deal with this upgrade at a later date. I tried running

sudo apt-get install nginx=1.6.2-1+trusty0

But got the following error

The following packages have unmet dependencies:
 nginx : Depends: nginx-full (< 1.6.2-1+trusty0.1~) but 1.8.0-1+trusty1 is to be installed or
                  nginx-light (< 1.6.2-1+trusty0.1~) but it is not going to be installed or
                  nginx-extras (< 1.6.2-1+trusty0.1~) but it is not going to be installed or
                  nginx-naxsi (< 1.6.2-1+trusty0.1~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
  • What are the contents of php-fpm error.log? – Tero Kilkanen May 12 '15 at 18:40
  • There is nothing regarding errors. Only two lines from the last couple of days in /var/log/php5-fpm.log [12-May-2015 09:48:48] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful [13-May-2015 09:11:22] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful – mr mojo risin May 13 '15 at 8:37
  • 1
    Ultimately it turned out the problem was most likely with php5-fpm... Unfortunately I'm not entirely sure what was the underlying issue but after reinstalling both php5-fpm and nginx I was able to access my sites locally. – mr mojo risin May 20 '15 at 12:47

This works for me


include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;


include fastcgi.conf;
| improve this answer | |
  • In which file you had made this changes, kindly give the path of file? – Tarunn Jul 12 '15 at 18:51
  • In your vhost file – zourite Jul 13 '15 at 1:19
  • Doesn't work. Same result. – PKHunter Feb 9 '16 at 14:53

Remove all nginx packets with:

aptitude purge nginx nginx-full

Than add official nginx deb repos:

deb http://nginx.org/packages/debian/ codename nginx
deb-src http://nginx.org/packages/debian/ codename nginx

wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key

Finally install nginx:

apt-get update
apt-get install nginx


It should work now. If not - see /var/log/nginx/error.log and fix errors.

| improve this answer | |

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.