HTTP

HTTP 502 Bad Gateway vs 524 A Timeout Occurred

Both HTTP 502 (Bad Gateway) and 524 (A Timeout Occurred) belong to the 5xx Server Error category. 502 indicates that the server, acting as a gateway or proxy, received an invalid response from the upstream server. Meanwhile, 524 means that cloudflare-specific. A TCP connection was established but the origin didn't respond with an HTTP response in time.

Description

The server, acting as a gateway or proxy, received an invalid response from the upstream server.

When You See It

When Nginx/Apache can't reach the application server (e.g., Gunicorn is down, upstream timeout).

How to Fix

Check if the upstream server is running. Verify proxy configuration. Check for upstream timeouts.

Description

Cloudflare-specific. A TCP connection was established but the origin didn't respond with an HTTP response in time.

When You See It

When a request to the origin takes longer than Cloudflare's 100-second timeout.

How to Fix

Optimize slow endpoints. Move long-running tasks to background jobs.

Key Differences

1.

HTTP 502: The server, acting as a gateway or proxy, received an invalid response from the upstream server.

2.

HTTP 524: Cloudflare-specific. A TCP connection was established but the origin didn't respond with an HTTP response in time.

3.

You encounter 502 when when Nginx/Apache can't reach the application server (e.g., Gunicorn is down, upstream timeout).

4.

You encounter 524 when when a request to the origin takes longer than Cloudflare's 100-second timeout.

When to Use Which

For 502 (Bad Gateway): Check if the upstream server is running. Verify proxy configuration. Check for upstream timeouts. For 524 (A Timeout Occurred): Optimize slow endpoints. Move long-running tasks to background jobs.

Learn More