What 504 means
The proxy reached the application, but the application did not respond within the proxy's timeout (nginx proxy_read_timeout, default 60 s; cloud load balancers often 30–60 s). The request may still be running on the backend after the client sees 504.
It usually points at a slow query, an external API call without a timeout, or a request that should have been made asynchronous.
Common causes
- Slow database query or lock contention.
- Outbound call to a third-party API hanging.
- CPU-starved application under load.
- Long-running export or report served synchronously.
How to fix it
- Find the slow request in the application logs or APM and fix the query or add a timeout to the outbound call.
- Move long work behind a job queue and return 202.
- Only raise the proxy timeout when the operation genuinely needs longer, and align every layer (CDN, LB, proxy, app).
What it looks like
A typical response:
HTTP/1.1 504 Gateway Timeout Server: nginx Content-Type: text/html <html><head><title>504 Gateway Time-out</title></head>…
The same event in an nginx access log (the status is the number after the request line):
203.0.113.7 - - [10/Sep/2026:10:12:01 +0000] "GET /api/report HTTP/1.1" 504 153 "-" "Mozilla/5.0"
Check it with curl
-i prints the status line and headers, and -w '%{http_code}' prints only the number, which is handy in scripts and health checks. Replace the URL with yours:
curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://example.com/api/orders
Compare what curl sees with what the browser sees. A different status from the same URL usually means a cache, a CDN edge or a cookie is in the way.
Investigating a run of 504s? Paste the log excerpt into Log Share to get line numbers, highlighting and an expiring link for whoever is on call with you.
Related status codes
502Bad Gateway: A proxy or load balancer got an invalid response from the upstream server.503Service Unavailable: The server is temporarily unable to handle the request.408Request Timeout: The client took too long to send the request.
FAQ
Why does my request time out at exactly 60 seconds?
That is the default proxy_read_timeout in nginx and a common load balancer idle timeout. The backend is slower than that; fixing the backend beats raising the timeout.
Is the backend still working after a 504?
Often yes. The proxy dropped the connection, but the application may complete the work, which is why non-idempotent requests must not be retried blindly.