Question

502 Bad Gateway after droplet reboot

I powered off the droplet to take a snapshot. After powering it back on, I’m getting a 502 Bad Gateway error.

I saw multiple questions on the same topic but none of the solutions worked for me.

I tried restarting nginx & php-fpm but no effect. Both seem to be running OK… UFW also allows connections on ports 80 & 443.

CPU/RAM/DISK usage on the droplets seems way below limit.

I also tried to restore the droplet from a 2-week old backup (when it was for sure working), but that didn’t work either.

I’ve ran some of the common commands below, with outputs included

/var/log/nginx/error.log output:

2020/11/19 11:41:54 [error] 29003#29003: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 99.10.79.177, server: example.com, request: "GET /wordpress HTTP/2.0", upstream: "http://127.0.0.1:8000/wordpress", host: "example.com"
2020/11/19 11:41:54 [error] 29003#29003: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 99.10.79.177, server: example.com, request: "GET /favicon.ico HTTP/2.0", upstream: "http://127.0.0.1:8000/favicon.ico", host: "example.com", referrer: "https://example.com/wordpress"
nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

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) Drop-In: /etc/systemd/system/nginx.service.d └─override.conf Active: active (running) since Wed 2020-11-18 19:24:38 PST; 16h ago Docs: man:nginx(8) Process: 1113 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS) Process: 1037 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 838 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 1102 (nginx) Tasks: 9 (limit: 2361) CGroup: /system.slice/nginx.service ├─1102 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ├─1104 nginx: worker process └─1105 nginx: cache manager process

Nov 18 19:24:36 example systemd[1]: Starting A high performance web server and a reverse proxy server… Nov 18 19:24:38 example systemd[1]: Started A high performance web server and a reverse proxy server.

systemctl status php7.2-fpm

● php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-11-18 19:55:51 PST; 15h ago Docs: man:php-fpm7.2(8) Main PID: 9167 (php-fpm7.2) Status: “Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec” Tasks: 3 (limit: 2361) CGroup: /system.slice/php7.2-fpm.service ├─9167 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf) ├─9187 php-fpm: pool www └─9188 php-fpm: pool www

Nov 18 19:55:51 example systemd[1]: Stopped The PHP 7.2 FastCGI Process Manager. Nov 18 19:55:51 example systemd[1]: Starting The PHP 7.2 FastCGI Process Manager… Nov 18 19:55:51 example systemd[1]: Started The PHP 7.2 FastCGI Process Manager.

netstat -plant
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      29000/nginx: master 
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      663/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      931/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1231/master         
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      29000/nginx: master 
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      962/mysqld          
tcp        0    340 138.197.197.242:22      99.10.79.177:58923      ESTABLISHED 27637/sshd: root@pt 
tcp        0      0 138.197.197.242:443     99.10.79.177:61303      ESTABLISHED 29003/nginx: worker 
tcp6       0      0 :::80                   :::*                    LISTEN      29000/nginx: master 
tcp6       0      0 :::22                   :::*                    LISTEN      931/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1231/master         
tcp6       0      0 :::8090                 :::*                    LISTEN      503/apache2      

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
November 19, 2020
Accepted Answer

Hi there @geochanto,

From the error log output that you’ve provided, it looks like your Nginx service is trying to connect to another service that is supposed to be listening on port 8000.

You need to find out which service is supposed to listen on that port and start it. One way to do that would be to use the history command to see some past commands that were executed on the server and possibly lead you to the service that you are looking for.

Another possibility is that your Nginx is trying to connect to Apache as the backend. Form the output of the netstat command it looks like that the Apache service is listening on port 8090 rather than 8000, what I could suggest is visiting your server IP or domain name on the Apache’s port dicectly (eg. http://yourdomain.com:8090) and see if you get your website server there.

Here is a quick video demo that shows a similar scenario:

Let me know how it goes! Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more