Mastering Nginx High‑Availability: A Complete Guide to Master‑Slave Setup
This article explains the Nginx master‑slave architecture, how a virtual IP is shared between a primary and backup server using Keepalived and VRRP, and why this simple failover design provides high availability for web services with minimal resources.
What is Nginx Master‑Slave?
In a master‑slave deployment two servers are used: a master that handles all client traffic and a backup (slave) that stays idle until the master fails. The master binds a virtual IP (VIP) so that clients always connect to the same address.
Architecture Overview
The master server provides services on the VIP, while the backup monitors the master’s health. When the master becomes unavailable, the backup takes over the VIP, ensuring uninterrupted service. The diagram below illustrates the layout.
How It Works
The failover relies on Keepalived implementing the VRRP protocol, which moves the virtual IP between nodes. The master holds the VIP and sends heartbeat messages to the backup. If the heartbeat stops, the backup seizes the VIP, promotes itself to master, and continues handling requests. Scripts monitor Nginx’s health and adjust node priorities dynamically.
Key Benefits
High availability with automatic VIP failover.
Simple deployment without additional load‑balancer hardware.
Suitable for environments with limited server resources but strict uptime requirements.
<ol><li>用户请求</li><li>↓</li><li>[VIP:192.168.1.100]</li><li>↓</li><li>┌──────────────────────────┐</li><li>│Keepalived│</li><li>└──────────────────────────┘</li><li>↓ ↓</li><li>[Nginx-Master][Nginx-Backup]</li></ol>Architect Chen
Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.
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.
