HTTP 504 Gateway Timeout
HTTP 504 Gateway Timeout means a gateway or proxy did not get a response from the upstream server in time. The backend is running but too slow, often because…
Quick answer
HTTP 504 Gateway Timeout means a gateway or proxy did not get a response from the upstream server in time. The backend is running but too slow, often because of long database queries, slow third-party APIs or a proxy timeout that is shorter than the work takes.
Last updated · Maintained by FreeAIToolz · How we test
What does HTTP 504 Gateway Timeout mean?
Each layer has its own timeout. Nginx proxy_read_timeout defaults to 60 seconds, AWS ALB idle timeout to 60 seconds, Cloudflare returns 524 after 100 seconds, and serverless functions have their own maximum duration.
| Status code | 504 |
|---|---|
| Name | Gateway Timeout |
| Class | 5xx Server Error |
| Defined in | RFC 9110 §15.6.5 |
| Cacheable by default | No, unless Cache-Control says so |
| Safe to retry automatically? | Yes, with backoff |
What causes HTTP 504?
- Slow database queries or missing indexes.
- Slow or hanging third-party API calls.
- Proxy or load-balancer timeouts shorter than the request’s processing time.
- Serverless function timeouts.
How do I fix HTTP 504?
- Profile and speed up the slow endpoint (indexes, caching, pagination).
- Add timeouts to outbound calls so they fail fast.
- Move long jobs to a background queue and return 202.
- Raise proxy timeouts only when the work legitimately takes longer.
What should a client do after HTTP 504?
Retry with backoff; consider a longer client timeout for known slow operations.
Does HTTP 504 affect SEO?
Slow responses reduce crawl rate; repeated 504s can lead to de-indexing. Aim for fast server responses (under about 600 ms TTFB).
Example 504 response
HTTP/1.1 504 Gateway Timeout
Date: Mon, 01 Dec 2026 12:00:00 GMT
Content-Type: application/json
{"error":{"status":504,"message":"Gateway Timeout"}} How to return 504 Gateway Timeout in code
Express (Node.js)
res.status(504).json({ error: 'Gateway Timeout' }); Next.js route handler
return Response.json({ error: 'Gateway Timeout' }, { status: 504 }); FastAPI (Python)
raise HTTPException(status_code=504, detail="Gateway Timeout") PHP
http_response_code(504); Nginx
location = /example {
return 504;
} Other 5xx status codes
The server failed to fulfil a valid request. Retrying later, with backoff, is usually reasonable.
- 500 Internal Server Error
- 501 Not Implemented
- 502 Bad Gateway
- 503 Service Unavailable
- 505 HTTP Version Not Supported
- 507 Insufficient Storage
- 508 Loop Detected
- 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
Frequently asked questions
504 vs 502?
How do I increase the timeout in Nginx?
Is 504 a client or server error?
Related
- 502 Bad Gateway HTTP 502 Bad Gateway means a server acting as a gateway or proxy (Nginx, a load balancer, Cloudflare) got an i.
- 524 A Timeout Occurred Cloudflare error 524 means Cloudflare connected to your origin, but the origin did not send an HTTP response w.
- 408 Request Timeout HTTP 408 Request Timeout means the server closed the connection because the client took too long to send the c.
- 499 Client Closed Request HTTP 499 Client Closed Request is a non-standard code logged by Nginx when the client closed the connection be.
- Open the HTTP Status Codes Reference → Free, no signup.