// http 5xx · server error
HTTP 504 Gateway Timeout
An upstream server didn't respond in time.
What HTTP 504 Gateway Timeout means
504 Gateway Timeout means a proxy or gateway didn't get a response from an upstream server in time. Like 502 it's about the upstream, but here the upstream was too slow rather than broken.
Which category is it?
504 is a 5xx code — Server error. 5xx means the server failed to fulfil an apparently valid request. It's the server's responsibility, not the caller's.
Common causes
- An upstream service responding too slowly
- A long-running query or request exceeding the timeout
- Network issues between proxy and origin
How to fix it
- Speed up or optimise the slow upstream operation
- Raise the gateway timeout if the work is legitimately long
- Check connectivity between the proxy and origin
Example 504 response
HTTP/1.1 504 Gateway Timeout
Content-Type: text/html
<h1>The upstream server took too long to respond</h1>How to diagnose a 504
- Identify the layer returning 504: a CDN, load balancer, reverse proxy or API gateway. Its logs usually name the upstream and the timeout that fired.
- Time the same request directly against the origin, bypassing the proxy. If the origin is slow, the 504 is a symptom of slow work, not of the proxy.
- Find the slow operation: long database queries, slow third-party calls, or heavy report generation inside a normal request.
- Compare proxy timeout settings with the real duration of the work. Common defaults range from tens of seconds to a few minutes.
504 compared with similar codes
- 502: 502 means the upstream answered with something invalid or the connection failed. 504 means the upstream did not answer in time.
- 503: 503 means the service says it cannot handle the request. 504 happens at a gateway that was left waiting.
- 408: 408 is the server waiting too long for the client's request. 504 is a gateway waiting too long for the server behind it.
504 Gateway Timeout: common questions
How do I fix a 504 Gateway Timeout?
Speed up the slow upstream operation, move long work to a background job, or raise the gateway timeout if the work is legitimately long. Also check for network problems between the proxy and origin.
Is a 504 temporary?
Often. A retry can succeed if the upstream was briefly overloaded, but repeated 504s on the same request point to work that exceeds the timeout.