Question

502 Bad Gateway nginx/1.18.0 (Ubuntu)

Posted January 28, 2021 10k views
Nginx

I have deployed the MERN stack project successfully . But now i am getting 502 Bad Gateway nginx/1.18.0 (Ubuntu). however the server is not running properly i am not able to fetch the backend data .please resolve this problem so that i will get out from this error.

Thanks

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.

×
Submit an Answer
4 answers

Hello @dailychoices2020,

Thanks for reaching out. A 502 Bad Gateway Error is a general indicator that there’s something wrong with a website’s server communication. Since it’s just a generic error, it doesn’t actually tell you the website’s exact issue. I recommend you to first check the Nginx error logs for more information.

/var/log/nginx/error.log

You can also refer to our Community answer here for more details
https://www.digitalocean.com/community/questions/502-bad-gateway-nginx-2?answer=62972

Hope this helps!

Cheers,
Lalitha

Hi @dailychoices2020,

In order to fix the issue, I’ll recommend you checking the Nginx errorlog. This errorlog will provide you with the exact reason behind the 502 Bad Gateway error you received on Nginx.

If unsure, you should be able to find where your error_log file is located from your /etc/nginx folder in the configuration file of your domain.

If you find the error, post it here so that we can give some suggestions on how to proceed.

Regards,
KFSys

i have done this test with this command as well /var/log/nginx/error.log. However i found that there are some controllers in my web Application and routes it’s showing the same way as i have coded but i am getting confused how to fix it

If you are still getting an error after following all the steps at the link in @Lalitha’s answer, check pm2 is running pm2 list
If not, check you’re in the correct directory then pm2 start ./(your-server.js)
This is assuming you have installed pm2