HTTP 504 — Gateway Timeout
HTTP 504
Gateway Timeout
A proxy or gateway waited for the server behind it and gave up before an answer arrived.
What 504 actually means
Like a 502, this comes from an intermediary reporting on the server behind it — but here the upstream was alive and simply too slow. The proxy hit its timeout and returned an error rather than waiting forever. That distinction matters when debugging: a 502 points at a process that is down or unreachable, a 504 points at one that is running but stuck, usually on a slow query, an external API call, or a lock.
Common causes
- A slow database query, often one missing an index
- An external API call the application makes with no timeout of its own
- A request doing too much work synchronously — a large report or export
- A deadlock or lock contention holding the request open
- The upstream saturated, so requests queue behind others
- A proxy timeout set lower than the application's own worst-case response time
If you're just trying to view the page
- Wait and retry — a slow query or a busy period often clears
- If it happens on one heavy action, such as generating a report, try a smaller date range or fewer items
- Check the status page; a 504 across a whole site means the operators already know
- Nothing on your side will speed the server up
If it's your site
- Find the slow operation before raising any timeout — a longer timeout turns a fast failure into a slow one
- Check the database slow query log and add the missing index; this is the single most common root cause
- Set explicit timeouts on every outbound HTTP call the application makes, so one slow dependency cannot consume a request slot indefinitely
- Move long work to a background job and return 202 with a status URL instead of holding the connection
- If you must raise the limit, raise `proxy_read_timeout` (Nginx) or the load balancer idle timeout — and remember the smallest timeout in the chain wins
- Watch for cascading failures: one slow dependency can saturate the pool and turn into site-wide 504s
Reference
- Status code
- 504
- Reason phrase
- Gateway Timeout
- Category
- 5xx — Server Error
- Cacheable by default
- No
- Defined in
- RFC 9110 §15.6.5
Common questions
- What does HTTP 504 mean?
- A proxy or gateway waited for the server behind it and gave up before an answer arrived. Like a 502, this comes from an intermediary reporting on the server behind it — but here the upstream was alive and simply too slow. The proxy hit its timeout and returned an error rather than waiting forever.
- How do I fix a 504 error?
- Wait and retry — a slow query or a busy period often clears
- Is 504 a client error or a server error?
- 504 is in the 5xx range, which means server error. The request was acceptable but the server could not fulfil it, so retrying later can succeed.
Related pages
- 500 Internal Server Error Something went wrong on the server and it has no more specific code to describe
- 502 Bad Gateway A proxy or gateway reached the server behind it and got back a broken response,
- 503 Service Unavailable The server is temporarily unable to handle the request, usually because it is ov
- 524 A Timeout Occurred Cloudflare connected to the origin successfully but the origin did not finish re
- 521 Web Server Is Down Cloudflare could not connect to the origin server because it refused the connect
- 522 Connection Timed Out Cloudflare tried to open a connection to the origin server and never got a reply
- 520 Web Server Returned an Unknown Error Cloudflare reached the origin server but got back a response it could not make s
- 525 SSL Handshake Failed The TLS handshake between Cloudflare and the origin server failed.
- 526 Invalid SSL Certificate The origin server presented a TLS certificate that Cloudflare could not validate
- 530 Origin DNS Error A Cloudflare error shown alongside a 1xxx error code that carries the real expla
- 501 Not Implemented The server does not support the functionality needed to fulfil the request, usua
- 511 Network Authentication Required You need to log in to the network itself — this is a captive portal, not the sit