Operations 3 min read

Achieving Nginx High Availability with Keepalived: Active‑Passive Setup Explained

To prevent single‑point failures of Nginx at the traffic entry, this guide explains why high availability is essential, outlines typical risks, and details a production‑grade Active‑Passive solution using Keepalived and VRRP to automatically fail over a virtual IP within seconds.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Achieving Nginx High Availability with Keepalived: Active‑Passive Setup Explained

Nginx usually sits at the front‑end of traffic flow; if the single instance goes down, the entire backend becomes unreachable, making high availability (HA) a must for any production service.

Typical single‑point risks include server crashes, unexpected Nginx process exits, network jitter, and human errors such as accidental reloads or deployments.

The most common, mature HA pattern for Nginx is to pair it with Keepalived using the VRRP protocol. One server holds a virtual IP (VIP); when the master node fails or its Nginx process exits, the VIP automatically migrates to the backup node, usually within 1–3 seconds, providing seamless failover.

<ol>
<li>用户请求</li>
<li>↓</li>
<li>VIP (e.g., 10.0.100:80/443) ←漂移的虚拟 IP</li>
<li>↓</li>
<li>┌───────────────┐
│ 主 Nginx (Master) │ ←优先级高,持有 VIP
└───────┬───────┘
│ 10.0.11 │
└────┴────┘
│
│ ┌──┴──┐
│ │
│ 从 Nginx (Backup) │ ←优先级低,VIP漂移后接管
│ 10.0.12 │
└──────────────────┘
↓
后端服务集群(Tomcat/Go/Node/PHP 等)</li>
</ol>

In this Active‑Passive configuration, the master Nginx handles all incoming traffic while the backup remains on standby. Keepalived monitors the master via heartbeat; upon detecting a failure, it triggers the VIP to float to the backup, which then takes over without client awareness.

This approach is especially suitable for scenarios sensitive to session stickiness or shared state, as the failover preserves the same IP address and port, ensuring continuity for downstream services.

By integrating Keepalived with Nginx, operators achieve a reliable, low‑latency HA solution that safeguards the entry point of web applications.

high availabilityVRRPKeepalivedActive-Passive
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

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.