HTTP

HTTP 502 Bad Gateway vs 504 Gateway Timeout

Both HTTP 502 (Bad Gateway) and 504 (Gateway Timeout) 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, 504 means that the server, acting as a gateway or proxy, did not receive a timely response from the upstream server.

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

The server, acting as a gateway or proxy, did not receive a timely response from the upstream server.

When You See It

When an upstream server is too slow to respond within the proxy's timeout window.

How to Fix

Increase proxy timeout settings. Optimize upstream server performance. Check for long-running queries.

Key Differences

1.

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

2.

HTTP 504: The server, acting as a gateway or proxy, did not receive a timely response from the upstream server.

3.

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

4.

You encounter 504 when when an upstream server is too slow to respond within the proxy's timeout window.

When to Use Which

For 502 (Bad Gateway): Check if the upstream server is running. Verify proxy configuration. Check for upstream timeouts. For 504 (Gateway Timeout): Increase proxy timeout settings. Optimize upstream server performance. Check for long-running queries.

Learn More