The HTTP 502 Bad Gateway error means a server acting as a gateway or proxy received an invalid or empty response from an upstream server it was relying on to fulfill your request. In plain terms: the front-facing server is fine and reachable, but the server behind it that was supposed to do the real work did not answer properly. The 502 is the messenger reporting a broken handoff between two servers — not a problem with your browser.
This guide explains what 502 means, why it happens, how to fix it from both sides, how it differs from the other 5xx errors, and what a 502 signals when you are routing through a proxy. For the broader set, see proxy server error codes.
Modern sites rarely serve traffic from a single machine. A request typically passes through a gateway — a reverse proxy, load balancer, or CDN like Cloudflare — which forwards it to an upstream application server. When that upstream returns something invalid (or nothing at all), the gateway cannot complete the request and reports a 502. The relationship between these layers is exactly what we cover in reverse proxy vs load balancer and forward proxy vs reverse proxy.
| Code | Meaning |
|---|---|
| 500 Internal Server Error | Generic failure inside the server handling the request |
| 502 Bad Gateway | Gateway/proxy got an invalid response from upstream |
| 503 Service Unavailable | Server temporarily overloaded or in maintenance |
| 504 Gateway Timeout | Gateway/proxy got no response from upstream in time |
The quick distinction: 502 means the upstream answered badly; 504 means it did not answer in time; 500 is the server's own internal fault; 503 means it is up but deliberately unavailable right now.
If you see a 502 only when routing requests through a proxy, the picture is slightly different. It can mean the proxy could not get a valid response from the target, often because the target is genuinely down or because a low-quality proxy node is failing. With reliable residential proxies the latter is rare; on free or overloaded proxies it is common — another reason to avoid free proxies. The right response is to retry through a different IP: a robust scraper treats an occasional 502 as a signal to rotate and retry rather than to abort. For building that retry logic, see Python requests retry.
It means a server acting as a gateway or proxy received an invalid or empty response from the upstream server it relies on. The front-facing server is working, but the server behind it that should have produced the response did not answer correctly. It is a broken handoff between servers, not a browser problem.
As a visitor, no — it is a server-side problem on the website's infrastructure. You can reload, clear your cache, or wait, but the actual fix has to happen on the server, where the upstream that failed lives.
Confirm the upstream application server is running and healthy, read the gateway and app logs to see what the upstream returned, check whether a recent deploy left the app unable to boot, tune timeouts if the backend is too slow, and verify firewall and DNS so the gateway can reach the upstream.
Both involve a gateway and an upstream server. A 502 Bad Gateway means the upstream returned an invalid response. A 504 Gateway Timeout means the upstream returned no response within the allowed time. 502 is a bad answer; 504 is no answer in time.
It usually means the proxy could not obtain a valid response from the target — either the target is down, or a low-quality proxy node failed. This is common on free or overloaded proxies and rare on reliable residential networks. The fix is to retry through a different IP.
Often, yes — many 502s are transient, caused by a brief upstream hiccup or restart, and a reload after a moment succeeds. If it persists, the upstream server has a real problem that the site owner must address.
A 502 Bad Gateway is a broken conversation between servers: the gateway is fine, but the upstream behind it answered badly or not at all. As a visitor you reload and wait; as an owner you check the upstream, the logs, and recent deploys. Through a proxy, a stray 502 is just a cue to rotate to a fresh IP and retry.
For scraping pipelines that need to shrug off the occasional gateway error, reliable IPs matter. SpyderProxy residential proxies start at $1.75/GB with 10M+ IPs across 195+ countries, automatic rotation, and city-level targeting.