在搭建系统时遇到了前端请求固定分发到一台remote_addr。经过查看nginx的acc日志发现
remote_addr为具体的某个ip,nginx中配置的是ip-hash算法来负载。初步断定是由于remote_addr为固定ip原因造成,经过查前端F5发现做了nat转换。
对应nginx不是未最前端时,如果前端做了代理,造成remote_addr为固定ip时可以采用下列方式解决。
1、首先要在代理服务器上开启_x_forwarded_for,将用户真实ip插入到http_x_forwarded_for中。
2、在nginx中配置map映射获取真实ip。map写在http模块中
map $http_x_forwarded_for $clientRealIp {
"" $remote_addr;
~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr;
}
3、upstream中的ip-hash改成hash $clientRealIp;
当nginx作为非前端服务器,并且前端F5做了nat转换,导致remote_addr固定,从而引发ip-hash负载不均问题。解决办法是:1. 代理服务器开启_x_forwarded_for,将真实ip放入http_x_forwarded_for;2. nginx配置map获取真实ip;3. 将upstream中的ip-hash改为hash $clientRealIp。
818

被折叠的 条评论
为什么被折叠?



