spyderproxy

HTTP 502 Bad Gateway: What It Means & How to Fix (2026)

D

Daniel K.

|
Published date

Mon May 25 2026

|8 min read

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.

What 502 Bad Gateway Means

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.

Common Causes

  • The upstream server is down. The application server crashed or was stopped, so the gateway gets nothing.
  • The upstream is overloaded. Under heavy load it returns malformed responses or drops connections.
  • A bad deploy. The application failed to start after a release, so the gateway has nothing healthy to talk to.
  • Firewall or network issues. Something between the gateway and upstream blocks or breaks the connection.
  • DNS problems. The gateway cannot resolve the upstream's address.
  • CDN cannot reach origin. With Cloudflare in front, a 502 often means the CDN could not get a valid response from your origin server.

How to Fix It (Visitor Side)

  1. Reload the page. Many 502s are transient and clear on a retry.
  2. Try in a few minutes. If the upstream is restarting, give it time.
  3. Clear cache and cookies. Rules out a stale local response.
  4. Check if the site is down for everyone. A status checker confirms it is not just you.

How to Fix It (Site Owner Side)

  1. Check the upstream is running. Confirm the application server or backend process is up and healthy.
  2. Read gateway and app logs. The reverse proxy (NGINX, etc.) and the app logs will show what the upstream returned.
  3. Verify a recent deploy. If the app failed to boot after a release, fix or roll back.
  4. Check timeouts and limits. An upstream that is too slow can trip the gateway's timeout — tune it or speed up the backend.
  5. Inspect firewall and DNS. Make sure the gateway can reach and resolve the upstream.

502 vs 500 vs 503 vs 504

CodeMeaning
500 Internal Server ErrorGeneric failure inside the server handling the request
502 Bad GatewayGateway/proxy got an invalid response from upstream
503 Service UnavailableServer temporarily overloaded or in maintenance
504 Gateway TimeoutGateway/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.

502 When You Use a Proxy

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.

Frequently Asked Questions

What does 502 Bad Gateway mean?

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.

Is a 502 error my fault?

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.

How do I fix a 502 error on my site?

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.

What is the difference between 502 and 504?

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.

Why do I get 502 errors through a proxy?

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.

Does refreshing fix a 502 error?

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.

Conclusion

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.

Reliable IPs That Don't Drop the Ball

Reliable nodes mean fewer gateway errors and clean retries. SpyderProxy residential proxies from $1.75/GB — 10M+ IPs, 195+ countries, rotation, and city-level targeting.