HTTP 504 · 5XX RFC 9110 §15.6.5 Cacheable: No Retryable: Yes (idempotent only)

HTTP 504 Gateway Timeout: Root Causes & Production Fix Guide

HTTP 504 Gateway Timeout means your reverse proxy or load balancer connected to the upstream server, but the upstream did not finish responding before `proxy_read_timeout` (default 60s in Nginx/AWS ALB) expired.

Top Root Causes of HTTP 504

Nginx Timeout Tuning & Async Job Pattern for 504

location /api/reports/ {
    proxy_connect_timeout 15s;
    proxy_send_timeout 180s;
    proxy_read_timeout 180s;
    proxy_pass http://127.0.0.1:3000;
}
# Better long-term fix: return 202 Accepted + job_id and poll /jobs/:id

Verify with cURL

curl -i -sS -w '\nTTFB: %{time_starttransfer}s Total: %{time_total}s\n' https://api.example.com/api/reports/export

Interactive Stack Diagnoser (HTTP 504)

Frequently Asked Questions

What is the default Nginx proxy_read_timeout?

60 seconds. Note that `proxy_read_timeout` measures the interval between two successive read operations, not the entire response duration.

Should I just raise timeouts to 600s to fix 504?

Only as a short-term workaround. Long synchronous requests tie up worker threads and still fail behind Cloudflare's 100s limit—move heavy work to an async queue returning 202 Accepted.

How do I diagnose which layer caused a 504?

Measure `time_starttransfer` with curl: 60s usually points to Nginx/ALB, 29s points to AWS API Gateway, and 100s points to Cloudflare 524.

Related Status Guides & Header Tools