HTTPfy

504 Gateway Timeout

A gateway or proxy did not get a response from the upstream server in time.

504 at a glance

Code
504
Name
Gateway Timeout
Class
5xx Server error
Status
IANA-registered standard code
Defined in
RFC 9110, Section 15.6.5
Cacheable by default
No by default. Caches store it only when the response carries explicit freshness (Cache-Control max-age, s-maxage or Expires).

What 504 means

504 Gateway Timeout is produced by an intermediary (nginx, a load balancer, a CDN, an API gateway) that connected to or waited on the upstream server and gave up before a response arrived. The upstream may still be working on the request, so retrying a non-idempotent request after a 504 can do the work twice.

What typically causes a 504

  • nginx proxy_read_timeout (60 s by default) or fastcgi_read_timeout expiring: "upstream timed out (110: Connection timed out) while reading response header".
  • AWS ALB: the target did not respond within the idle timeout (60 s by default).
  • Amazon API Gateway: integration timeout (29 s by default for REST APIs).
  • Amazon CloudFront: origin response timeout (30 s default).
  • Slow database queries, locks, or calls to slow third-party APIs.
  • Behind Cloudflare, an origin that is too slow shows as 524 rather than 504.

Fix it on the server

  • Find the slow part: application timings and database slow-query logs are faster than raising timeouts.
  • Move long work to a background job and return 202 with a status URL.
  • If a long request is legitimate, raise timeouts consistently at every layer, innermost lowest.

Fix it as a client or visitor

  • Retry idempotent requests with backoff; for POSTs, check whether the action happened before retrying.

Headers that go with 504

HeaderRole
ServerShows which layer timed out.

Example response

HTTP/1.1 504 Gateway Timeout
Server: nginx
Content-Type: text/html

<title>504 Gateway Time-out</title>

Opens the HTTP headers tool with your URL filled in; it shows the status line and headers of every redirect hop.