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

Using ip_hash on a SINGLE upstream server only in nginx

· 52CE 我爱测

We are using nginx for load balancing. We just pushed a new server online with a massive upgrade to our platform for testing before we roll it out. We want to make sure it's working for, so we have weights set to send roughly 10%…

问题原文

原帖链接 · JoshL · CC BY-SA 3.0

We are using nginx for load balancing. We just pushed a new server online with a massive upgrade to our platform for testing before we roll it out. We want to make sure it's working for, so we have weights set to send roughly 10% of the traffic to that server.

The problem is that we need to ensure that if the user is servers that server, they will always get that server for future sessions. This is easily done with ip_hash, but what we really want is for the other services to use a round-robin strategy while ONLY that one server uses ip_hash.

Is something like that possible at all? Here is our upstream.conf

upstream apps  {
   ip_hash;
   server 10.134.13.38:80 weight=3; # app-00
   server 10.134.13.46:80 weight=3; # app-01
   server 10.134.24.30:80 weight=3; # app-02
   server 10.134.8.153:80 weight=1; # app-new-test
}

已采纳解答

原帖链接 · Alexey Ten · CC BY-SA 3.0

I would use split_clients directive and define two upstreams.

upstream apps {
   server 10.134.13.38:80; # app-00
   server 10.134.13.46:80; # app-01
   server 10.134.24.30:80; # app-02
}

upstream apps_new_test {
   server 10.134.8.153:80; # app-new-test
}

split_clients "${remote_addr}AAA" $upstream_app {
    10% apps_new_test;
    *   apps;
}

server {
    ...
    proxy_pass http://$upstream_app;
}

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

资料来源与适用范围

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

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

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