Nginx ip_哈希不平衡连接

Nginx ip_哈希不平衡连接,nginx,Nginx,如果在上游模块中启用了ip_hash,我无法使nginx达到负载平衡。当我移除它时,负载平衡工作,但我需要粘性会话。我做错了什么 map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream backend { ip_hash; server localhost:3900 max_fails=3 fail_timeout=5s; server lo

如果在
上游
模块中启用了
ip_hash
,我无法使
nginx
达到负载平衡。当我移除它时,负载平衡工作,但我需要粘性会话。我做错了什么

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;
    }
}

我在一台机器上运行所有测试,因此所有连接都具有相同的IP地址,并且由于粘性会话而放在相同的服务器上