What a 502 error means for visitors and site owners
A 502 means two servers failed to talk to each other. The front server (a CDN, load balancer, or Nginx) reached the server behind it and got no usable answer. The problem is on the website's side, and it's usually short-lived.
If you're visiting a site:
- Wait a minute and reload. Many 502s happen while a site restarts or deploys.
- Try another browser or network, or clear your browser cache, to rule out a cached error page.
- If the site stays down, it's an outage on their end. Check their status page.
If you run the site:
- Check that the upstream application (Node, PHP-FPM, Gunicorn, and so on) is running and listening on the port your proxy points to.
- Read the proxy's error log. Nginx logs lines like
upstream prematurely closed connectionorconnect() failedwith the cause. - Look for crashes or out-of-memory kills in the app, and for timeouts set lower on the proxy than the app needs.
- Behind Cloudflare or another CDN, make sure your origin firewall allows the CDN's IP ranges and that the origin's SSL setup matches the CDN setting.
What a 502 Bad Gateway means
Think of the gateway or proxy as a receptionist who passes your request to a back office. A 502 means the receptionist got the message through to the back office (the "upstream" server) but the reply came back broken or unreadable. So the failure happens between the edge (the front-facing server) and the origin (the real backend) — not in your request. Because it's a 5xx error, it's a server-side problem and usually clears up on its own.
Why scrapers see 502
When scraping, a 502 usually points to something flaky on the path to the site: an unreliable proxy, an origin server that's overloaded, or a CDN (content delivery network — the cache layer that fronts many sites) that can't reach the backend. It can also show up briefly when an anti-bot edge mishandles or drops a request it finds suspicious. Unlike a 403 (which is a hard "access denied"), a 502 is generally worth retrying.
How to fix a 502 error
Retry with exponential backoff and jitter — that means waiting a bit longer between each attempt and adding a small random delay so retries don't all hit at once. Most 502s clear on their own. If they persist, the gateway between you and the origin is the real problem: swap to a more reliable proxy pool, lower concurrency (fewer requests at once) so you're not overwhelming a fragile origin, and check whether your proxy provider — not the target site — is the one returning the 502. Persistent 502s that only appear on protected URLs can mean an edge is dropping you; in that case a real-browser unblock flow via Web Access API is more stable.
