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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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 commandnetstat -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