php-fpm

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
nginx/1.14.0

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 installation and configuration

The configuration is nginx HTTP server, PHP FastCGI Process Manager (PHP-FPM), and the Alternative PHP Cache (APC).

Installation

The first step is to download the nginx software from the Nginx website. If using the Ubuntu distribution, following are the steps,

(i) Download the nginx signing keys from the Nginx website,

$ wget http://nginx.org/keys/nginx_signing.key

(ii) Add this key to the apt keyring,

$ sudo apt-key add nginx_signing.key

(iii) Add the following lines at the end of the file, /etc/apt/sources.list

deb http://nginx.org/packages/ubuntu/ version-code nginx
deb-src http://nginx.org/packages/ubuntu/ version-code nginx

In the above two lines, replace version-code, with the value for the relevant Ubuntu version.… Read more