实际上我有一个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 requestsBasically, 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
upstream backend { server main.example.com max_fails=3 fail_timeout=30s; server backup1.example.com backup; }backup
marks the server as a backup server. It will be passed requests when the primary servers are unavailable.
In this case backup will only be used when main is down
更多推荐
发布评论