Operations 4 min read

How Does Nginx Detect Unhealthy Servers? Passive vs Active Health Checks Explained

NGINX determines server health through passive checks—stopping forwarding after failures—and active health checks, which periodically probe each backend using the health_check directive, allowing configuration of intervals, failure thresholds, custom URIs, and response matching criteria to ensure reliable load balancing.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How Does Nginx Detect Unhealthy Servers? Passive vs Active Health Checks Explained

If a server in an upstream group fails, NGINX stops forwarding requests to it; to know whether a server is healthy, NGINX performs health checks.

Passive Check

When a request forwarded to a server fails or receives no response, NGINX marks the server as unavailable and stops sending traffic for a timeout period. By default, a single failure triggers a 10‑second pause, but the number of failures (max_fails) and the timeout (fail_timeout) can be configured, e.g.:

upstream backend {
    server backend1.example.com;
    server backend2.example.com max_fails=3 fail_timeout=30s;
    server backend3.example.com max_fails=2;
}

Active Check

NGINX can also actively probe each server at regular intervals, without waiting for real traffic. This is enabled with the health_check directive, typically together with a zone definition:

upstream backend {
    zone backend 64k;
    server backend1.example.com;
    ...
}
server {
    location / {
        proxy_pass http://backend;
        health_check;
    }
}

The default active check sends a request to “/” every 5 seconds; a failure, timeout, or non‑2xx/3xx status marks the server as down.

Customizing Active Checks

Interval and thresholds : health_check interval=10 fails=3 passes=2; checks every 10 seconds, requires three consecutive failures to mark down and two consecutive successes to mark up.

Check URI : health_check uri=/some/path; changes the request path from “/” to a custom one.

Response matching : Define a match block to require specific status codes, headers, or body content, e.g.:

match server_ok {
    status 200-399;
    header Content-Type = text/html;
    body !~ "maintenance mode";
}
...
health_check match=server_ok;

Using these settings, NGINX can reliably detect unhealthy backends and maintain high availability.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Operationsload balancinghealth checkactive checkpassive check
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.