Operations 3 min read

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.

Architect Chen
Architect Chen
Architect Chen
Mastering Nginx High‑Availability: A Complete Guide to Master‑Slave Setup

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.

Nginx master‑slave architecture diagram
Nginx master‑slave architecture diagram

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>
high availabilitymaster‑slaveNginxVRRPKeepalived
Architect Chen
Written by

Architect Chen

Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.