Operations 4 min read

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.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
How Nginx Master‑Slave Architecture Ensures High Availability

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.

Nginx master‑slave architecture diagram
Nginx master‑slave architecture diagram
Nginx master‑slave workflow diagram
Nginx master‑slave workflow diagram
High AvailabilityMaster‑SlavenginxFailoverVirtual IPKeepalived
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

login 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.