Why do I get 502 Bad Gateway with nginx reverse proxy to my node app?
#1
I’ve been trying to set up a reverse proxy for my home server to handle a couple of subdomains, but I keep running into 502 Bad Gateway errors. I’m using Nginx on a VPS, and my backend is a Node.js app on a different port, but the requests just aren’t getting through.
Reply
#2
I ran into this too. The upstream wasn't answering. My Node server was listening on 127.0.0.1:3001 but Nginx proxy_pass pointed at 3000. When I curl -s http://127.0.0.1:3000 from the VPS I got connection refused. After changing the port to the one Node actually used and restarting, the 502 vanished.
Reply
#3
I had a 502 once when the Node process kept dying on load due to an exception. I checked the logs, found a crash on startup, fixed a missing env var that pointed to a wrong DB URL, and restarted. The error didn’t show up after that, at least for a while.
Reply
#4
Are you sure the upstream port is reachable from the VPS? Have you tried curl from the server to the Node port to confirm?
Reply
#5
I kept wandering through the SSL and headers, but often it was a stale Nginx config or a trailing slash in proxy_pass. I drifted off topic once and then came back to the same port mismatch habit, and it still felt unsettled.
Reply


[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Forum Jump: