504 Gateway Timeout means a gateway or proxy did not receive a timely response from an upstream server and gave up waiting. The backend is not necessarily dead, but it failed to finish responding within the proxy's time limit.
Where 502 means "the backend returned a broken response," 504 means "the backend was too slow and the response never arrived in time." Slow DB queries, overload, and lagging external APIs are common causes.
GET /api/report/heavy HTTP/1.1
Host: www.example.comHTTP/1.1 504 Gateway Timeout
Content-Type: text/html
Content-Length: 42
<html><body><h1>504 Gateway Timeout</h1></body></html>location /api {
proxy_pass http://backend;
proxy_connect_timeout 5s;
proxy_read_timeout 60s; # raise for legitimately slow endpoints
}# Measure how long the origin actually takes to respond
curl -o /dev/null -s -w 'time_total: %{time_total}s\n' \
http://127.0.0.1:3000/api/report/heavy