What a 502 means
A server acting as a gateway or proxy sends a 502 after contacting an upstream server but not receiving a valid response. On most websites, that sender is a reverse proxy, CDN or load balancer in front of the origin server. A proxy server you configured can also send it if its route upstream fails.
HTTP/1.1 502 Bad Gateway
Your client reached the gateway, so this differs from a local DNS or connection failure. Response headers such as Server and Via may show which layer produced the error.
Common causes
- The upstream closed the connection. A crash, restart or network interruption prevented a complete HTTP response.
- The response was malformed. The gateway received an invalid status line, header or protocol response.
- Routing or TLS failed. Gateways often map upstream DNS, routing or certificate problems to 502.
- The origin was overloaded. It accepted the connection but failed before returning a valid response.
How to fix it
- Identify the sender. Check the response body and headers for the name of a CDN, gateway or forward proxy.
- Compare direct and proxied requests. If the direct request works but the proxied one fails, the proxy path is the likely source. If both fail, the website is more likely at fault.
- Retry safe requests carefully. Use exponential backoff for GET or HEAD requests. Don’t automatically repeat a POST that could create duplicate actions.
- Reduce concurrency. If errors appear during request bursts, lower parallel requests and stay within the site’s limits.
- Check upstream systems. Site operators should inspect origin logs, health checks, DNS records, TLS settings and load-balancer configuration.
502 vs 503 vs 504
| Code | Sent by | Meaning |
|---|---|---|
| 502 Bad Gateway | Gateway or proxy | Invalid upstream response |
| 503 Service Unavailable | Website or gateway | Temporarily unable to handle the request |
| 504 Gateway Timeout | Gateway or proxy | Upstream did not respond in time |
FAQ
Is a 502 error caused by my proxy?
It can be. If the URL works directly but returns 502 only through the proxy, the proxy or its upstream route is the likely source. If both requests fail, the website’s gateway or origin is more likely responsible.
Does a 502 mean the website blocked my IP?
Usually no. IP blocks more often produce 403 or 429 responses. Some systems use nonstandard status codes, so compare the same request from an approved connection before deciding.
Should I retry a 502 error?
Yes, but only a few times with a delay for safe requests such as GET. Don’t repeatedly retry POST requests unless the application supports idempotency keys.