Health Checks and Failover
2 min read
- Authors
- Name
- Vijaykumar Rajendran
- @vijayrajendran_

Table of Contents
Health Checks and Failover
Passive Health Checks
Nginx automatically detects failed servers by monitoring responses:
upstream backend {
server s1:8080 max_fails=3 fail_timeout=30s;
server s2:8080 max_fails=3 fail_timeout=30s;
server s3:8080 max_fails=3 fail_timeout=30s;
server backup:8080 backup;
}
Settings:
max_fails=3- Mark down after 3 failuresfail_timeout=30s- Try again after 30 secondsbackup- Use only if all primary down
How It Works
- Nginx detects failed request to server1
- Counts as failure
- After 3 failures → marks server1 as DOWN
- Routes all traffic to server2 and server3
- After 30 seconds → tries server1 again
- If working → marks as UP
Production High Availability
upstream backend {
least_conn;
server backend1:8080 weight=2 max_fails=3 fail_timeout=30s;
server backend2:8080 weight=2 max_fails=3 fail_timeout=30s;
server backend3:8080 weight=1 max_fails=2 fail_timeout=30s;
server backup:8080 backup max_fails=1 fail_timeout=10s;
}
server {
location / {
proxy_pass http://backend;
proxy_connect_timeout 5s;
proxy_read_timeout 10s;
}
}
High availability achieved!