【问题标题】:Nginx Load Balancer Strategy - Traffic Always to the same serverNginx 负载均衡器策略 - 流量总是到同一台服务器
【发布时间】:2019-02-09 20:37:16
【问题描述】:

我在不同的大陆(美国和欧洲)有 2 个不同的上游

我希望每个服务器始终将流量发送到同一台服务器,但是我需要在每个服务器上指定 2 台服务器以防停机 - 流量应发送到备用服务器。

问题在于没有执行此操作的策略。我在首选服务器上做了 weight=1000000000 的解决方法,但我觉得这不是正确的方法。

upstream US_UPSTREAM  {
    ip_hash;
    server 2.2.2.2 weight=100000000 max_fails=10  fail_timeout=3600s;
    server 1.1.1.1 #should only be used as backup, not round robin or any other strategy
}

upstream EU_UPSTREAM {
    ip_hash;
    server 1.1.1.1 weight=100000000 max_fails=10  fail_timeout=3600s;
    server 2.2.2.2 #should only be used as backup, not round robin or any other strategy
}

【问题讨论】:

  • 你试过backup选项吗?
  • 是的,就是这样!谢谢

标签: nginx nginx-location nginx-reverse-proxy


【解决方案1】:

好的,终于找到解决方法了。

单独备份是行不通的。如果第一台服务器离线,我会从它那里得到 502。让它工作的关键是在第二台服务器上添加备份,并在位置设置错误:

location / {
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forward-Proto http;
      proxy_set_header X-Nginx-Proxy true;


      proxy_pass http://$preferred_upstream$request_uri;
      *proxy_next_upstream error http_502;*
}

上游

upstream eu_upstream {
    ip_hash;
    server 1.1.1.1 max_fails=5 fail_timeout=3600s;
    server 2.2.2.2 *backup*;
}

【讨论】:

    猜你喜欢
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 2018-03-10
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 2012-08-27
    相关资源
    最近更新 更多