What 504 means
A server acting as a gateway or proxy waited for the server behind it and didn’t get a reply in time.
When servers send it
When the application takes longer than the proxy’s timeout, often a slow database query, a report, or a call to another slow service.
Common causes
- A slow database query or a locked table.
- The app waiting on a third-party API that’s slow or down.
- Proxy timeouts set shorter than the work takes (nginx’s
proxy_read_timeoutdefaults to 60 seconds). - Serverless functions or load balancers with their own time limits.
- A network or firewall problem between proxy and app.
How to fix it as a developer
- Find the slow part: app logs, slow query logs and tracing will show it.
- Move long work to a background job and return 202 Accepted with a status URL.
- Add timeouts to your app’s own outgoing calls, shorter than the proxy’s timeout, so you can return a clear error instead.
- Only raise the proxy timeout if the work really needs longer.
How to fix it as a visitor
- Try again in a few minutes. The site is responding too slowly right now.
Related codes
- 502 Bad Gateway: A proxy or load balancer got an invalid response, or none at all, from the server behind it.
- 503 Service Unavailable: The server can’t handle the request right now, usually because it’s overloaded or down for maintenance.
- 408 Request Timeout: The server gave up waiting for the client to finish sending its request.
- 524 A Timeout Occurred: Cloudflare connected to the website’s server, but it took too long to send a response.
Where it’s defined
504 Gateway Timeout is defined in RFC 9110, section 15.6.5. It’s a 5xx code, the server error class: the server, or something behind it, failed to deal with a valid request.
Other 5xx codes
500 Internal Server Error · 501 Not Implemented · 502 Bad Gateway · 503 Service Unavailable · 505 HTTP Version Not Supported · 511 Network Authentication Required · 520 Web Server Returned an Unknown Error · 521 Web Server Is Down · 522 Connection Timed Out · 523 Origin Is Unreachable · 524 A Timeout Occurred · 525 SSL Handshake Failed · 526 Invalid SSL Certificate
Or search them all in the HTTP status code list.
Questions people ask
What does HTTP 504 Gateway Timeout mean?
How do I fix a 504 Gateway Timeout in nginx?
proxy_read_timeout (or fastcgi_read_timeout for PHP) above the 60-second default.