Operations 3 min read

Master‑Slave Nginx HA with Keepalived: Architecture, Principles, and Failover Steps

This article explains how to build a highly available Nginx deployment using a master‑slave architecture combined with Keepalived, detailing the role of virtual IPs, the failover mechanism, and the step‑by‑step process that ensures 99.99% uptime.

Architect Chen
Architect Chen
Architect Chen
Master‑Slave Nginx HA with Keepalived: Architecture, Principles, and Failover Steps

Why a Master‑Slave Nginx Architecture?

In high‑performance systems a single Nginx instance becomes a single point of failure; if it crashes the entire backend service goes down. To achieve 99.99% availability, a common solution is to pair Nginx with Keepalived, forming a master‑slave high‑availability (HA) setup.

Key Components

Master node (MASTER) : Holds the virtual IP (VIP) and handles all traffic under normal conditions.

Backup node (BACKUP) : Continuously monitors the master’s health and stays in hot‑standby mode.

VIP (Virtual IP) : A floating address bound to the master’s network interface; when the master fails, the VIP automatically migrates to the backup, allowing clients to continue using the same address without awareness of the underlying change.

How Keepalived Enables Failover

Keepalived implements the VRRP protocol to manage the VIP between the master and backup. The backup node detects a loss of heartbeat from the master, claims the VIP based on priority calculations, and instantly becomes the new master, ensuring seamless traffic redirection.

Architecture Overview

The overall layout consists of two identical Nginx servers, each running Keepalived with almost identical configurations. Both servers share a single VIP that clients (browsers, apps, upstream services) always target.

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

Failover Process

Master fails → Keepalived heartbeat lost → Backup detects failure → Backup takes over VIP → Backup becomes new Master

After the backup assumes the VIP, it starts handling all incoming requests, effectively becoming the new master. The original master can later rejoin as a backup after recovery.

Why Nginx + Keepalived Is a Classic HA Solution

This combination provides a simple, reliable, and widely adopted method to eliminate single‑point failures for web traffic, making it a go‑to choice for many large‑scale deployments.

high availabilitymaster‑slavevirtual IPKeepalived
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.