Question

502 Bad Gateway After Reboot

Hi DO Team,

My droplets is working good before i power off for a long time ( 2 week ), and today i’m trying to power on my droplet, it show 502 Bad Gateway in the browser. And in the terminal when i’m trying to run pm2 restart server.js, it show … Use --update-env to update environments variables… I dont know how to fix it and make my server run again ( try to run pm2 start server.js --update-env but it not work…). Note: i’m using Nodejs + MongoDb + Nextjs and server is Ubuntu 18.04. Thank you.


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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

In my case when I checked the pm2 list, it seemed processes were running. So I just reloaded them using command.

  • pm2 reload <process>

Everything were okay, but in fact staging and production app still threw 502 bad gateway.

So I stopped processes and restarted them, and then everything were really worked.

  • pm2 stop <process>
  • pm2 restart <process>

I think after restarting the droplet, need to drop or stop the process and then restart that.

Hope it helps you!

@bobbyiliev:

tail -100 /var/log/nginx/error.log shows me the following for our application after restarting mongodb :

2020/01/16 16:26:44 [error] 25305#25305: *69279 upstream prematurely closed connection while reading response header from upstream, client: 128.227.182.203, server: lims.rgportal.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3001/", host: "lims.rgportal.com"
2020/01/16 16:28:44 [error] 25305#25305: *69279 upstream prematurely closed connection while reading response header from upstream, client: 128.227.182.203, server: lims.rgportal.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3001/favicon.ico", host: "lims.rgportal.com", referrer: "https://lims.rgportal.com/"
2020/01/16 16:29:53 [error] 25305#25305: *69298 upstream prematurely closed connection while reading response header from upstream, client: 128.227.1.38, server: lims.rgportal.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3001/", host: "lims.rgportal.com"
2020/01/16 16:30:01 [error] 25305#25305: *69307 upstream prematurely closed connection while reading response header from upstream, client: 128.227.1.36, server: lims.rgportal.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3001/", host: "lims.rgportal.com", referrer: "https://lims.rgportal.com/"
2020/01/16 16:30:01 [error] 25305#25305: *69298 upstream prematurely closed connection while reading response header from upstream, client: 128.227.1.38, server: lims.rgportal.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3001/favicon.ico", host: "lims.rgportal.com", referrer: "https://lims.rgportal.com/"
2020/01/16 16:30:01 [error] 25305#25305: *69307 connect() failed (111: Connection refused) while connecting to upstream, client: 128.227.1.36, server: lims.rgportal.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3001/favicon.ico", host: "lims.rgportal.com", referrer: "https://lims.rgportal.com/"

Hello,

The problem that you are seeing is not really related to a droplet problem, it is definitely due to your application not running at the moment.

I would recommend starting with the following:

  • Check your Nginx error log for more information:
tail -100 /var/log/nginx/error.log

Feel free to share the error here so I could advise you further.

  • Share the error that you get when you try to start your application.

Regards, Bobby