In nginx, what is the purpose of the max_fails and fail_timeout parameters in an upstream block?
Think about how nginx decides to stop sending requests to a failing backend server temporarily.
The max_fails parameter sets how many failed attempts to connect to a server are allowed within the fail_timeout period. If the number of failures reaches max_fails, nginx marks the server as down for the duration of fail_timeout.
Given this nginx upstream configuration:
upstream backend {
server backend1.example.com max_fails=3 fail_timeout=10s;
}If backend1 fails 4 times within 10 seconds, what will nginx log?
Check what nginx logs when it disables a server due to failures.
When the number of failed attempts exceeds max_fails within fail_timeout, nginx disables the server temporarily and logs an error indicating the server is disabled.
You want nginx to mark a backend server as down after 2 failed attempts and keep it down for 15 seconds. Which configuration snippet achieves this?
Remember max_fails is the failure count, fail_timeout is the duration the server stays down.
Setting max_fails=2 means after 2 failures nginx marks the server down. fail_timeout=15s means the server stays down for 15 seconds before retrying.
An nginx server is marked down too often even though the backend is healthy. The config is:
server backend.example.com max_fails=1 fail_timeout=30s;
What is the most likely cause?
Consider how sensitive nginx is to failures with these settings.
With max_fails=1, nginx marks the server down after just one failure, which can cause frequent down states even for transient issues.
Consider this nginx upstream config:
server backend1.example.com max_fails=3 fail_timeout=20s;
Which sequence correctly describes what happens when backend1 fails 3 times in 10 seconds, then recovers after 25 seconds?
Think about the order: failure, marking down, timeout expiration, recovery.
First failures happen (1), then nginx disables the server (2). After fail_timeout expires, failure count resets (4), then nginx resumes sending requests (3).