Back to Status Codes
Server Error (5xx)

HTTP 502 Bad Gateway

The server received an invalid response from an upstream server while acting as a gateway.

502

Bad Gateway

The server received an invalid response from an upstream server while acting as a gateway.

What Causes HTTP 502?

  • Upstream server is down or unreachable
  • Proxy or load balancer configuration error
  • Upstream server returned an invalid response
  • Network connectivity issues between services
  • Upstream server timeout

Code Examples

See how HTTP 502 responses look in different programming languages and tools.

curl -X GET https://api.example.com/resource
# Response: 502 Bad Gateway
# The gateway/proxy cannot reach the upstream server

How to Fix HTTP 502

  • Check if upstream services are running and healthy
  • Verify proxy and load balancer configurations
  • Implement health checks for upstream services
  • Add retry logic with exponential backoff
  • Monitor upstream service availability

Related Status Codes

Test Your APIs

Frequently Asked Questions

What does HTTP 502 mean?

The server received an invalid response from an upstream server while acting as a gateway.

What causes HTTP 502?

Upstream server is down or unreachable. Proxy or load balancer configuration error. Upstream server returned an invalid response. Network connectivity issues between services. Upstream server timeout

How to fix HTTP 502?

Check if upstream services are running and healthy. Verify proxy and load balancer configurations. Implement health checks for upstream services. Add retry logic with exponential backoff. Monitor upstream service availability

http 502bad gateway errorhttp status codesapi error handlingrest api server error