Learn Labs
Operations

Failure Scenarios

How an Nginx edge breaks, measured in this lab

Nginx itself rarely crashes. What breaks is everything around it: backends, configuration, certificates, limits. Every row below was produced in this module's labs.

failureGET okclientfastno extra waitcachedreads1 app stopped✓!✓1 app hung✓!✓POST to hung app✗✗all apps down✗✓✓backend slower than timeout✗✗✓nginx reload!✓✓broken config reloaded✓✓✓

One backend stopped or hung

GETs keep succeeding: failed attempts are retried on another instance. The cost is latency for the first requests to find out: the connect timeout (2 s here) for a stopped backend, the read timeout (5 s) for a hung one, until max_fails takes it out of rotation for fail_timeout. Then it's probed with a real request every 10 seconds.

Signal: [warn] upstream server temporarily disabled and [error] upstream timed out in the error log; several addresses in the access log's upstream field.

A POST to a hung backend

504 after the location's read timeout, never retried. Correct behaviour, which the client has to handle: retry with an idempotency key, or report the error.

All backends down

uncached /api/whoami: 502 in 0.00s
200 STALE    took  0.00s, data is 12s old      # cached route, proxy_cache_use_stale

Cached routes keep serving stale data; everything else fails fast with 502 (Nginx knows there are no live servers).

A backend slower than the timeout

504 after two full timeouts (10 s), with the work done twice. Retries on timeout amplify load exactly when the backend is overloaded.

A backend that changed IP

Without resolve, Nginx keeps the old address until reload: the moved instance gets no traffic, and if something else now has the old address, requests reach the wrong service.

Reloads and broken configs

5 reloads under load: {200: 1365, 'RemoteProtocolError': 2}
reload with an invalid config: [emerg] host not found in upstream ... (old config keeps serving)

A reload is graceful, apart from a race on idle keepalive connections that clients must retry. A broken config is refused by the running master. Start with nginx -t in CI, and never restart to apply config: a restart with a broken config means no Nginx at all.

The rest

ScenarioWhat happensSignal
Certificate expiresEvery client refuses to connectTLSCertificateExpiringSoon 14 days ahead
Rate limit too tightLegitimate bursts get 429429 share in logs; the failover lab hit it
worker_connections reachedNew connections droppedaccepted − handled > 0, worker_connections are not enough in the error log
Disk fullCache writes and logs fail; temp files for buffered bodies failError log, node disk alerts
Unknown names and spoofed headersServed as if legitimateCatch-all server, overwrite X-Forwarded-For
A 404 cached for a yearUsers keep a broken asset after the fixCache-Control on error responses (always)

Lab

  1. Reproduce each scenario and note the first signal you'd have seen without the lab printing it.
  2. Set worker_connections 64, reload, and flood the server. Find the error log line.
  3. Fill the cache volume (dd a big file into /var/cache/nginx) and request a cached URL. What happens?

On this page