Webpage no longer loading after resetting root password for droplet. 502 error

I have been asked to help a colleague with a web application hosted on a digital ocean droplet. The application was initially created and maintained by someone who is no longer contactable, no one really knows what the application was written in, but they now need to make some changes and would like to be able to connect to the database.

After speaking with support at digital ocean they advised me I needed to reset the root password (it was unknown) I did that this morning but now the website is offline with a gateway 502 error.

If I try to load the webpage, I get this error in the logs.

2022/09/04 21:46:48 [error] 8165#8165: *42 connect() failed (111: Connection refused) while connecting to upstream, client:, server:, request: "GET / HTTP/1.1", upstream: "", host: ""

If I check the status of nginx,

root@adi:/# sudo 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 Sun 2022-09-04 21:16:56 UTC; 33min ago
  Process: 8144 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/ (code=exited, status=0/SUCCESS)
  Process: 8160 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 8157 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 8164 (nginx)
    Tasks: 2
   Memory: 1.9M
      CPU: 73ms
   CGroup: /system.slice/nginx.service
           ├─8164 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           └─8165 nginx: worker process

Sep 04 21:16:56 adi systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 04 21:16:56 adi systemd[1]: nginx.service: Failed to parse PID from file /run/ Invalid argument
Sep 04 21:16:56 adi systemd[1]: Started A high performance web server and a reverse proxy server.

Here I see an error regarding parsing the PID file, from some research it suggests this is a common bug caused by the systmd trying to read the file before nginx created it, and suggests the follow (which I have not done yet, as I am a total noob with this and dont want to break anything.)

Step 1. Create the directory /etc/systemd/system/nginx.service.d Create a directory named nginx.service.d in /etc/systemd/system/:

mkdir /etc/systemd/system/nginx.service.d Should the system complain that it already exists, ignore and move on to Step 2.

Step 2. Print data to file Execute:

printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf

This is a one-liner. printf will write its output into the configuration file /etc/systemd/system/nginx.service.d/override.conf.

Step 3. Reload the daemon Reload systemd manager configuration:

systemctl daemon-reload This will rerun all generators, reload all unit files and recreate the entire systemd dependency tree.

Step 4. Restart NGINX This line will restart NGINX for you:

systemctl restart nginx The error should be fixed now. Any help or suggestions on how to get the website back up and running?


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
September 9, 2022

Hi there,

The error that you are seeing means that your Nginx service is unable to connect to your backend service that is supposed to be running on port 5000.

This means that the Nginx service itself is running well, but the backend service is not.

The backend service might be a Docker container, a Node app or any other service that you’ve initially configured when you deployed your app.

Here is a quick video that describes this:

What you could do is try and run the history command so you could find out what service was initially started on port 5000.

Let me know how it goes!



Try DigitalOcean for free

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

Sign up