I have used this tutorial here to deploy my Nodejs application. I have followed up on everything correctly but I noted when I edited my location / on my server block in this file /etc/nginx/sites-available/example.com file from this,
location / {
try_files $uri $uri/ =404;
}
to this
location / {
proxy_pass http://localhost:5000;
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;
}
I get a 502 Bad Gateway error on my website. Can someone help me fix that?
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!
Hello,
The “502 Bad Gateway” error often indicates that Nginx is unable to communicate with the upstream server, in this case, your Node.js application running on port 5000.
Here are a few things that you should check:
Ensure that your Node.js application is running and correctly listening on localhost:5000. You can check this with the command netstat -plant | grep 5000 from the server’s terminal.
If your application is not listening on port 5000, you would need to change the proxy rule in your Nginx configuration to match the port that your app is listening on. Also, verify that your Nginx configuration for proxying is correct and there are no typos. The configuration you’ve posted looks correct, but ensure there are no conflicting server blocks. You can use the nginx -t command to do a quick Nginx config test.
Look at both the Nginx error logs (/var/log/nginx/error.log) and your Node.js application logs to see if there are any reported issues that could be causing the error.
Here is a quick video that also might be helpful!
Best,
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.