How Nginx Master‑Slave Architecture Ensures High Availability
This article explains how Nginx's master‑slave (primary‑backup) setup, combined with Keepalived and a virtual IP, provides high‑availability for web and API services by automatically detecting failures, shifting the VIP, and allowing the backup server to take over without service interruption.
Nginx is a critical middleware in large‑scale architectures. This article explains the master‑slave (primary‑backup) mode used to achieve high availability (HA), where a backup server takes over when the primary fails.
Typical scenarios include core business systems requiring HA, public‑facing web/API services, internal data‑center service disaster recovery, and replacing single‑point Nginx deployments.
Principle
The master‑slave setup does not modify Nginx’s processing logic; instead it relies on auxiliary mechanisms such as Keepalived to control roles, virtual IP (VIP) floating, and automatic failover.
Architecture Components
Role
Description
Master
Provides services, binds VIP, handles external requests.
Backup
Standby, does not bind VIP, continuously monitors the master.
Keepalived
Manages role assignment and VIP distribution.
Virtual IP (VIP)
Unified external address that can migrate between master and backup.
Workflow
The master binds the VIP and runs Nginx to serve client requests.
Keepalived runs on the master, performing health checks.
The backup also runs Keepalived, monitoring the master’s status.
If the master fails, Keepalived triggers failover, moves the VIP to the backup, and starts Nginx on the backup.
When the original master recovers, it can reclaim the VIP.
Through this mechanism, service interruption is avoided even in high‑traffic or critical applications.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.