Nginx Active Health Checks and Recovery: Readiness, Drain and Safe Testing
Health has several meanings
A process may accept TCP connections while its application cannot serve useful traffic. Liveness asks whether a process is functioning; readiness asks whether it should receive requests now. A shallow readiness endpoint should be cheap, bounded and return meaningful status. Do not make a probe execute a real purchase or other state-changing action.
GET /ready -> 200 ready (application can serve catalog)GET /ready -> 503 unavailable (application not ready)TCP connect succeeds -> process listening; readiness unknownPeriodic checks in NGINX Plus
The commercial HTTP health-check module sends requests independently of client traffic. It uses a shared upstream zone. The default HTTP success criteria accept 2xx and 3xx statuses; a named match can narrow this to the exact readiness contract. The interval, consecutive failures and consecutive passes govern removal and recovery. These controls do not establish that an entire user workflow works.
match catalog_ready { status 200;}upstream checked_catalog { zone checked_catalog 64k; server 127.0.0.1:18191; server 127.0.0.1:18192;}server { listen 127.0.0.1:18190; location / { proxy_pass http://checked_catalog; health_check uri=/ready interval=5s fails=2 passes=2 mandatory match=catalog_ready; }}The mandatory option makes peers wait for an initial check before receiving traffic. With two failures required, two consecutive unsuccessful checks mark the peer unhealthy; two consecutive successes are required to restore eligibility. Actual transition timing depends on scheduling and check duration. The probe path is fixed; a successful readiness check is not a guarantee against immediate failure.
Initial: checking200, 200 -> healthy503, 503 -> unhealthy200, 200 -> healthyRecovery and planned maintenance
Passive detection is useful on Open Source; active checks require the relevant licensed module or a separately designed external readiness mechanism. Do not add a commercial directive to an OSS config and expect it to work. A recovered peer can experience a burst of new traffic. Commercial slow_start ramps effective weight over time; verify its balancing-method restrictions. The upstream server drain parameter allows existing bound requests rather than new unbound traffic; it became available in Open Source in 1.29.6. Drain is not a guarantee that every in-flight operation finished.
# NGINX Plus: gradual weight recoveryserver 127.0.0.1:18191 slow_start=30s;# OSS 1.29.6+ or supported Plus: bound-session drainserver 127.0.0.1:18192 drain;Treat these as independent syntax examples, not a full group. If sessions live only in a failed process, redirecting a request to another peer may lose session state. Store session data in a suitable shared service or design stateless application requests. Keep deadlines, retries and available capacity explicit.
Measure a controlled outage and recovery
The optional lab uses a primary and backup, one worker, fixed loopback ports and read-only responses. Confirm the primary marker, stop only the lab primary, observe retry and backup behavior, then restart it and observe recovery after the exclusion interval. The backup remains healthy during the exercise. Check both the returned body and upstream log. The OSS fixture does not run active health checks; the Plus and DNS examples are documentation-backed, not execution evidence.
Use an approved unprivileged disposable environment and finite requests. A successful toy test cannot guarantee production availability, session continuity or exactly-once writes.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx Active Health Checks and Recovery: Readiness, Drain and Safe Testing
Design a health-check policy and distinguish edition-specific features from ordinary Open Source failover.
What is readiness?
Which module provides periodic HTTP health_check?
What does mandatory do?
What does drain allow?
Why may failover break sessions?