1

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   127.0.0.1:9000;
        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: 127.0.0.1, 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.
mr mojo risin
  • 111
  • 1
  • 3
  • 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 08: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
  • You need to check the php-fpm error log. – Michael Hampton Sep 05 '21 at 20:26

2 Answers2

0

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

https://nginx.org/en/linux_packages.html

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

techraf
  • 4,243
  • 8
  • 29
  • 44
Oleg Abrazhaev
  • 173
  • 1
  • 9
0

This works for me

replace

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

with

include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
zourite
  • 101
  • 2