Nginx负载平衡第二台服务器接管第一台服务器是否失败(Nginx load balancing second server takes over if the first fails)

编程入门 行业动态 更新时间:2024-10-09 04:17:14
Nginx负载平衡第二台服务器接管第一台服务器是否失败(Nginx load balancing second server takes over if the first fails)

实际上我有一个Nginx配置,有两台服务器负载均衡,我想实现这种行为:

第一台服务器(主要服务器)应该向所有人提供所有请求 如果主服务器由于某种原因失败,则第二台服务器应该接管所有请求

基本上,第二台服务器应该作为主服务器的备份。 当然我可以使用这两个因素:第一台服务器上的max_fails = 3 fail_timeout = 15s但是如何确保主要服务器的使用是独占的,避免了默认的循环行为? 谢谢。

I've actually an Nginx configuration with two servers in load balancing and I would like to achieve this behavior:

the first server (the main one) should serve all the requests to everybody if the main server fails for some reason, the second server should take over all the requests

Basically, the second server should act as a backup of the main one. Of course I could use the two factors: max_fails=3 fail_timeout=15s on the first server BUT how to ensure that the usage of the main one is exclusive, avoiding the default round-robin behavior? Thanks.

最满意答案

您需要使用上游的backup属性

备用

将服务器标记为备份服务器。 当主服务器不可用时,它将被传递请求。

upstream backend { server main.example.com max_fails=3 fail_timeout=30s; server backup1.example.com backup; }

在这种情况下,备份仅在main关闭时使用

You need to use the backup attribute for the upstream

backup

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

upstream backend { server main.example.com max_fails=3 fail_timeout=30s; server backup1.example.com backup; }

In this case backup will only be used when main is down

更多推荐

本文发布于:2023-08-06 09:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   负载   第一台   Nginx   load

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!