504 Gateway Timeout

A proxy timed out waiting for upstream.

5xx · Server error

What it means

A gateway or proxy didn't get a response from the upstream server in time.

Compared with 502: the upstream didn't answer badly, it didn't answer at all before the proxy gave up.

Why you're seeing it

  • Slow database queries or long reports.
  • An upstream that's overloaded or stuck.
  • Proxy timeouts set lower than the app's real response time, such as nginx's 60-second proxy_read_timeout default.
  • Cloudflare uses its own code, 524, when your origin takes too long.

How to fix it

  • Find what's slow on the upstream and optimise it.
  • Move long work to a background job and return 202.
  • Only raise proxy timeouts if the slow request is expected.

Example response

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

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