Hi everyone,
I’m currently working on deploying my app on Ubuntu 20.04. I’m using a stack that includes Nginx, Node.js, and MongoDB, and I’m deploying via DigitalOcean Droplet.
Here’s the issue I’m facing on my website
I’ve reviewed the documentation for Nginx and other relevant software, but I’m still stuck.
Could anyone guide me on troubleshooting this or suggest useful resources? Any advice would be greatly appreciated!
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!
Hey there! 👋
I’ve answered a similar question in the past here:
https://www.digitalocean.com/community/questions/502-bad-gateway-nginx-2
A 502 Bad Gateway error usually means that Nginx is unable to connect to your backend server (in this case, Node.js). Here’s a checklist to help you troubleshoot and get things running smoothly!
sudo netstat -plnt | grep :<PORT_NUMBER>
Replace <PORT_NUMBER>
with the port your Node app is supposed to be listening on (e.g., 3000).curl http://localhost:<PORT_NUMBER>
If it responds correctly, Node.js is running fine./etc/nginx/sites-available/default
or /etc/nginx/sites-enabled/default
, and ensure it’s set up to proxy requests to the correct port where Node.js is running.server {
listen 80;
server_name your_domain.com;
location / {
proxy_pass http://localhost:<PORT_NUMBER>;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Remember to replace <PORT_NUMBER>
with the port your Node.js app is using.sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log
sudo systemctl restart nginx
pm2 restart <app_name>
On another note, if you’re handling a production environment, you might want to consider using DigitalOcean Managed Databases for MongoDB. Managed Databases handle backups, scaling, and recovery, which can make your life easier.
Let me know if any of this helps!
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.