Common causes
- A slow database query, a missing index or a locked table.
- The application calls another API that is slow or down, with no timeout of its own.
- Long-running work, such as an export or a report, done inside the request instead of in a background job.
- The application server is overloaded and requests wait in a queue.
- A network problem between the proxy and the application, so packets never arrive.
Find the slow part first
Raising the timeout hides the problem. Check the application's logs or traces for the request and see where the time goes. Once you know the slow step, fix it with an index, a cache or a background job. Raise the timeout only for requests that genuinely need longer.
Default timeouts
Every layer has its own timeout, so the shortest one between the client and the application decides when a 504 appears.
| Layer | Default | Setting |
|---|---|---|
| nginx | 60 seconds | proxy_read_timeout, and fastcgi_read_timeout for PHP-FPM |
| AWS Application Load Balancer | 60 seconds | Idle timeout in the load balancer attributes |
| Cloudflare | 100 seconds | After this, Cloudflare returns its own 524 error |
Raise the nginx timeout for one route
location /api/reports/ {
proxy_pass http://app:3000;
proxy_read_timeout 300s;
}Better: answer quickly and finish in the background
For work that takes minutes, return 202 Accepted with a job ID straight away, run the work in a queue, and let the client poll a status URL or receive a webhook when it's done.
Frequently asked questions
Is a 504 my fault or the server's?
It's a server-side problem. As a visitor, wait and try again. As the site owner, look for slow requests behind the proxy.
Does a 504 mean the request failed?
Not necessarily. The upstream may have finished the work after the proxy stopped waiting, so retrying a payment or an order can create a duplicate. Use idempotency keys for requests like these.
What is the difference between 504 and 408?
408 Request Timeout means the server waited too long for the client to send the request. 504 means a proxy waited too long for the upstream server to respond.
More http status code lookup guides
- 502 Bad Gateway: What It Means and How to Fix It
- 429 Too Many Requests: Meaning, Retry-After and Fixes
- 403 Forbidden: Meaning, Causes and How to Fix It
- 401 Unauthorized: What It Means and How to Fix It
- 500 Internal Server Error: Causes and How to Fix It
- 503 Service Unavailable: Causes and Fixes
- 400 Bad Request: Causes and Fixes (Including Cookie Too Large)
- 404 Not Found: What It Means and How to Fix It
- 301 Moved Permanently: Meaning, SEO and Examples
- 302 Found: Temporary Redirects Explained
- 408 Request Timeout: Causes and How to Fix It