nginx 502 Bad Gateway

1.0 502 Bad Gateway

nginx 502 Bad Gateway

After the update of Linux on the web server, the website would not open in the browser. Instead the following error was displayed.

502 Bad Gateway

2.0 Solution

First we check the nginx server.

$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-03-21 15:16:47 UTC; 16h ago
     Docs: man:nginx(8)
 Main PID: 1354 (nginx)
    Tasks: 8 (limit: 1158)
   CGroup: /system.slice/nginx.service
           ├─1354 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─1355 nginx: worker process

Warning: Journal has been rotated since unit was started.
Read more

nginx 502 Bad Gateway Error


A routine software update on the server running nginx was done. After that the website stopped opening in the browser window and 502 Bad Gateway error along with the nginx version number was displayed. Looking in the log file showed an entry like,

2014/06/26 11:09:53 [crit] 2539#0: *15 connect() to unix:/tmp/php-fpm.sock failed (13: Permission denied) while connecting to upstream, client:, server: www.example.com, request: "GET /foo HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "www.example.com"


The problem was solved after the following lines were un-commented in the file, /etc/php5/fpm/pool.d/www.conf

listen.owner = www-data
listen.group = www-data

The same file, /etc/php5/fpm/pool.d/www.conf, had the lines

user = www-data
group = www-data

Also, the nginx configuration file /etc/nginx/nginx.conf had the user and group settings,

user  www-data www-data;

See also

Read more