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.
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_staleCached 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
| Scenario | What happens | Signal |
|---|---|---|
| Certificate expires | Every client refuses to connect | TLSCertificateExpiringSoon 14 days ahead |
| Rate limit too tight | Legitimate bursts get 429 | 429 share in logs; the failover lab hit it |
worker_connections reached | New connections dropped | accepted − handled > 0, worker_connections are not enough in the error log |
| Disk full | Cache writes and logs fail; temp files for buffered bodies fail | Error log, node disk alerts |
| Unknown names and spoofed headers | Served as if legitimate | Catch-all server, overwrite X-Forwarded-For |
| A 404 cached for a year | Users keep a broken asset after the fix | Cache-Control on error responses (always) |
For each row, decide in advance: what the client sees, what alert fires, and what the on-call does. Half of these were found in this module only because a lab measured them. Run the labs against your own config.
Lab
- Reproduce each scenario and note the first signal you'd have seen without the lab printing it.
- Set
worker_connections 64, reload, and flood the server. Find the error log line. - Fill the cache volume (
dda big file into/var/cache/nginx) and request a cached URL. What happens?