Reputation: 5571
I cannot get nginx
to load balance with ip_hash
enabled in upstream
module. When I remove it load balancing works but I need sticky sessioning. What am I doing wrong?
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;
}
}
Upvotes: 0
Views: 1707
Reputation: 5571
I was running all tests from one machine so all connecteions had the same IP address and were put to the same server due to sticky sessioning.
Upvotes: 1