Nginx Upstream Peer Parameters, Backup Servers and Shared Zones
Primary and backup are different roles
upstream service_pool { server 127.0.0.1:18171 max_fails=2 fail_timeout=10s; server 127.0.0.1:18172 backup;}The backup receives work when primary peers are unavailable, not as an equal member during normal operation. down marks a peer deliberately unavailable. Backup is incompatible with hash, IP hash and random selection; do not combine methods arbitrarily. In a one-member group, the passive failure settings do not exclude that sole member.
Passive failure accounting is not continuous probing
In the fragment, qualifying failures within ten seconds can lead to temporary exclusion for ten seconds. Which failures count depends on the protocol-specific next-upstream rules. Zero max_fails disables failure accounting. A successful response does not prove business correctness, and a quiet pool has no incoming traffic from which to learn. Active periodic health checks and retries have separate semantics; do not promise exactly-once operations or blindly replay writes.
status=200 peer=127.0.0.1:18171, 127.0.0.1:18172 upstream=502, 200This example depicts a failed first attempt and successful second attempt. The client sees 200, but an operator can still detect the earlier issue. Multiple groups after internal redirects have additional delimiters; do not parse the address as a single host:port unconditionally.
Limit active connections and share worker state
upstream bounded_pool { zone bounded_state 64k; server 127.0.0.1:18171 max_conns=8; server 127.0.0.1:18172 max_conns=8;}Without a shared zone the active-connection limit is per worker; with a zone the upstream runtime state is shared across workers of this Nginx instance. Two workers without a zone could each use eight active connections to one peer. Idle cached connections can make total socket count exceed the active limit. A zone is not a distributed coordination service and does not share app sessions. A full pool can result in errors; an explicit upstream request queue is a separate commercial feature in the checked documentation.
upstream standby_demo { server 127.0.0.1:18171 down; server 127.0.0.1:18172 backup;}The lab declares a primary down rather than killing a process. This demonstrates eligibility, not timed passive recovery. Dynamic DNS with resolve and a shared zone is available in OSS from 1.27.3 according to the module reference; the older authoring build cannot be assumed to support it. Active failure timing, dynamic DNS, and multi-worker saturation need separate approved tests.
Plan safe changes and read the results
Start with known local peers, test the config, and run bounded read-only requests. Log attempt status privately and confirm the intended responder. If a peer is unavailable, inspect its own health and connection errors before increasing timeouts or weights. Do not declare a production failover guarantee from a static down example. The next chapter covers keepalive, buffering and timeouts.
Practice
Two workers serve A with max_conns=6 and no zone. Estimate the combined active limit for A, then explain the effect of adding a shared zone. Explain why a backup demonstration cannot prove passive failure recovery.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx Upstream Peer Parameters, Backup Servers and Shared Zones
Apply upstream selection concepts to original examples.
When is a backup normally eligible?
What does max_fails=0 do?
With two workers and no zone, what is max_conns=8 scoped to?
Does a zone share shopping cart data?
What does the static down example validate if run?