对WebService的应用程序利用Nginx进行分布式部署,upstream 的分配方式是ip_hash,但是,不同的IP(10.5.110.92-254)请求只被分配到其中一个server上,请问是什么问题?谢谢。
nginx.conf配置如下:
location / {
root html;
index index.html index.htm;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost;
}
upstream localhost {
ip_hash;
server 127.0.0.1:18777;
server 127.0.0.1:28777;
}
1楼(未知网友)
根据nginx 的wiki [1] ,
The key for the hash is the class-C network address of the client.
也就是ip_hash 里,根据的是client 的c 段,也就是 10.5.110.x ,都看做同一个client ,也就分配到同一个server 了。
-----
[1]: http://wiki.nginx.org/HttpUpstreamModule#ip_hash