Interview Prep/Networking/Load balancers and reverse proxies

nginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.

BeginnerTroubleshootingLoad balancers and reverse proxies
Answer

Likely causes → The connection to the upstream succeeded but the app didn't send response headers within proxy_read_timeout (60 s default). The request is slow (heavy query, lock, external call) or the app is overloaded.

Diagnose →

grep 'upstream timed out' /var/log/nginx/error.log | awk -F'request: ' '{print $2}' | sort | uniq -c | sort -rn | head
# add $upstream_response_time and $request_time to log_format to see distribution

Fix → Fix the slow endpoint (indexes, caching, async jobs for long work). Raise proxy_read_timeout only for specific known-long endpoints:

location /reports/ {
    proxy_read_timeout 300s;
    proxy_pass http://app;
}

Prevent → Log upstream timings, set SLO-based alerts on p99, and move long tasks to background workers with polling or callbacks.

All Networking questions Roadmap: Networking for DevOps

More on Load balancers and reverse proxies