Skip to content

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

Key points

  • "while connecting" and "while reading response header" mean different things.
  • Raising proxy_read_timeout hides slow requests.
  • Log $upstream_response_time.
  • Saturated backends produce a burst of them.

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.

Common causes

  • Slow database queries or remote calls.
  • All workers busy, so requests sit waiting.
  • The backend hung or deadlocked.
  • Long-running reports on a normal request path.
  • Network trouble to the upstream.

Diagnose it

The log line includes the exact URL and the upstream address.

bash
# 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.

Frequently asked questions

Should I increase proxy_read_timeout?

Only for specific routes that are legitimately slow.

What is the default timeout?

proxy_read_timeout defaults to 60 seconds.

Does the backend stop working when Nginx times out?

Often not. It may continue on a request nobody is waiting for.

Check it now, free

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.