NGINX 504 Gateway Timeout: Diagnosis From the Logs Out

Symptom

Requests hang for exactly 60s then return 504.

Root cause

The upstream did not answer within proxy_read_timeout (default 60s).

Fix, in order

1. Find which requests time outgrep " 504 " /var/log/nginx/access.log | awk '{print $7}' | sort | uniq -c
2. Raise timeout only after profiling the backendlocation / { proxy_read_timeout 120s; }
3. Check for slow queries or locks behind the endpointSHOW FULL PROCESSLIST; -- MySQL
4. Test backend latency directly, bypassing NGINXcurl -w "@ Transfer: %{time_total}s\n" -o /dev/null http://127.0.0.1:8000/slow-endpoint

Prevent it coming back

Set SLOs per endpoint and monitor upstream_response_time in your metrics.

Deep-dive article

Full walkthrough: NGINX 504 Gateway Timeout: Diagnosis From the Logs Out on the NinjaOps blog.

Run it on clean infra

Spinning up a fresh box to reproduce or escape this error?

Managed cloud hosting

Related

Cloud & DevOps tool comparisons · Hardware build guides

NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.

Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog