How do I fix 502 Bad Gateway with Nginx reverse proxy to a private backend?
#1
I’ve been trying to set up a reverse proxy for my home lab server to access a few web apps securely, but I keep running into 502 Bad Gateway errors. I’m using Nginx on a VPS, and my backend is on a different private IP, but the connection just won’t stay stable.
Reply
#2
That sounds familiar. Sometimes the 502 shows up even when nginx can reach the host, because the backend closes the connection or returns a bad gateway while it's still starting.
Reply
#3
DHCP on the backend caused the private IP to drift; once I assigned a static private IP and pinned a route, the proxy stopped flaking.
Reply
#4
I once pointed proxy_pass at a port the backend wasn't listening on; a quick curl showed it, and switching to the real port cured the 502.
Reply
#5
Question: are you sure the VPS can actually reach the private IP consistently? Could firewall rules be blocking the traffic in certain hours?
Reply
#6
TLS termination mismatch can cause 502 too; if nginx is talking TLS to a plain HTTP backend, you get that kind of error.
Reply
#7
I tried longer timeouts and enable keepalive, but the 502 would still show up during spikes and it turned out the backend process was crashing under load.
Reply
#8
I eventually isolated a small internal proxy in front of the backend just to sanity-check path; it stayed stable, so the issue looked like something in the path from the VPS to the LAN.
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: