我无法让nginx
与ip_hash
模块中启用的upstream
进行负载均衡。当我删除它负载平衡工作,但我需要粘性会话。我做错了什么?
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream backend {
ip_hash;
server localhost:3900 max_fails=3 fail_timeout=5s;
server localhost:3901 max_fails=3 fail_timeout=5s;
}
# Only retry if there was a communication error, not a timeout.
proxy_next_upstream error;
server {
server_name localhost;
listen 8300;
access_log /var/log/nginx/myapp.access.log;
# static file
location /assets/ {
root /location/to/statics/;
autoindex off;
}
# sockjs
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
答案 0 :(得分:1)
我从一台计算机上运行所有测试,因此所有连接都具有相同的IP地址,并且由于粘性会话而被放到同一台服务器上。