Troubleshooting guide
Nginx "upstream timed out (110)": how to fix it
Nginx waited for your application and gave up. The log line says which phase and which request, which is most of the diagnosis already.
3 min read11 sectionsUpdated
On this page
What it means
Nginx returns 504 and logs upstream timed out (110: Connection timed out). The text after it matters. "while connecting to upstream" means the TCP connection did not complete, so check the network or a backlog that is full. "while reading response header" means the backend accepted the request but did not answer in time, so the application is slow.
# Recent timeouts, with the phase and URL
sudo grep 'upstream timed out' /var/log/nginx/error.log | tail -5
# Which upstream and paths are affected
sudo grep 'upstream timed out' /var/log/nginx/error.log | grep -oE 'request: "[A-Z]+ [^ ]+' | sort | uniq -c | sort -rn | head
# Add timings to your log_format:
# rt=$request_time uct=$upstream_connect_time uht=$upstream_header_time urt=$upstream_response_time
# Current timeout values
sudo nginx -T 2>/dev/null | grep -E 'proxy_(connect|read|send)_timeout'Fixes
Find what the application was doing, using traces or a slow query log, and fix that. Move long work into background jobs. Increase workers if they are saturated but healthy. Raise proxy_read_timeout only for known slow routes, in their own location block. Set proxy_next_upstream with care, because retrying non-idempotent requests can repeat side effects such as payments.
Reading the timing fields
$upstream_connect_time near the timeout points at the connection step. A small connect time with a large $upstream_header_time means the backend accepted the request and took its time. A short header time with a long total time means the response started quickly but streamed slowly. Those three numbers tell you which layer to investigate before opening any other tool. Note that values can contain commas if Nginx tried more than one upstream, which itself is useful: it shows a retry occurred.
Catch it automatically
Chart 504s and upstream response time per location, and use APM to see which span used the time. See also Nginx monitoring and the 504 guide.
Check it now, free
- HTTP headers checker: See the raw response headers of any URL.
- Open port checker: Is a TCP port open, closed or filtered from the internet?
Related reading
- Cloudflare error 522: connection timed out: Fix Cloudflare error 522 "Connection timed out": the origin did not complete the TCP connection in time. Overloaded servers, dropped packets and wrong DNS.
- HikariCP "Connection is not available": how to fix it: Fix HikariCP Connection is not available, request timed out: use leak detection, size the pool sensibly, avoid long transactions and read pool metrics.
- Error: connect ETIMEDOUT: What ETIMEDOUT means, how it differs from ECONNREFUSED, the usual causes such as firewalls, security groups and wrong IPs, and how to set timeouts.
- Nginx "no live upstreams": how to fix it: Fix Nginx no live upstreams while connecting to upstream: how max_fails marks servers down, why one failure can empty a pool, and how to configure it properly.
- ERR_TUNNEL_CONNECTION_FAILED: how to fix it: Fix ERR_TUNNEL_CONNECTION_FAILED: proxy servers refusing HTTPS tunnels, wrong proxy settings, VPN apps and corporate filters, step by step.
- ERR_PROXY_CONNECTION_FAILED: how to fix it: Fix ERR_PROXY_CONNECTION_FAILED ("No internet, there is something wrong with the proxy server"): remove stale proxies, fix PAC files and VPN leftovers.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.