大网数据广告活动
服务器运维问答

How do multiple backup servers work in Nginx?

· 52CE 我爱测

For the backup directive, The Nginx documentation states rather minimally: marks the server as a backup server. It will be passed requests when the primary servers are unavailable. What if you have multiple backups and the primar…

问题原文

原帖链接 · Benny Bottema · CC BY-SA 3.0

For the backup directive, The Nginx documentation states rather minimally:

marks the server as a backup server. It will be passed requests when the primary servers are unavailable.

What if you have multiple backups and the primary server goes down, is one of the backups appointed the new primary? Or will Nginx Round Robin between them?

Context:

I have a primary server and multiple backups, but all connections should always go to the same primary or backup. Sort of like the ip_hash load balancing mode except it should use the same server for all connections and clients.

社区高分解答

原帖链接 · Devitgg · CC BY-SA 4.0

While it does not support multi-backup servers in a context as @Alberto Mendoza answered --

If you place the backups to another VPS running a NGINX load balancer to its own backups... this is a work around I am currently using for a multi-regional network.

upstream routing {
    server main_server:8080 max_fails=2 fail_timeout=5;
    server backupServer1:8080 max_fails=1 fail_timeout=5;
    server backupServer2:8080 backup;
}

If your main server is unresponsive for 2 fails -- it will attempt your first VPS backup -- if for some odd reason that is being DDOS or for whatever reason is down also -- it will go to your third VPS .. You can continue to daisy chain as needed.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-10-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。