Question

502 Bad Gateway After Reboot

Posted November 5, 2019 827 views
DigitalOceanUbuntu 18.04

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.

edited by bobbyiliev

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.

×
2 answers

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

@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/"
edited by MattIPv4
  • Hi @rtocco,

    It looks like that your backend application that should be listening on port 3001 is not up and running. You could try checking if this is true with this command here:

    • netstat -plant | grep 3001

    If you do not get any output then it would mean that your backend is not running and you would need to make sure that it is started.

    Hope that this helps!
    Regards,
    Bobby

    • Hi Bobby,

      The problem was with fork, i was trying to execute the fork command to start the mongodb instance and it used to lead to 502 error, but when i combined auth and fork, it worked fine. The command i used was :
      sudo mongod –fork –auth –port 27017 –dbpath /var/lib/mongodb –logpath /var/lib/mongodb/mongod.log

Submit an Answer