繁体   English   中英

AWS ELB - > nginx - > socket.io node.js粘性负载平衡

[英]AWS ELB -> nginx -> socket.io node.js sticky load balancing

我遇到了这个配置的问题。 我的AWS ELB接受端口80上的TCP连接,并使用代理协议将它们转发到侦听端口8080的nginx实例。此nginx节点应该使用ip_hash模块将用户粘贴到特定节点。

这工作得非常好,但是在4个节点中只有2个被使用而不是在所有节点之间进行负载平衡,这是我的nginx配置

upstream socket_nodes {
    ip_hash;
    server a.server.com:2000;
    server a.server.com:2001;
    server a.server.com:2002;
    server a.server.com:2003;
}

# Accept connections via the load balancer
server {
  listen 8080 proxy_protocol;
  set_real_ip_from 0.0.0.0/32;
  real_ip_header proxy_protocol;
  charset utf-8;
  location / {
      proxy_pass http://socket_nodes;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      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_set_header X-Forwarded-Proto $scheme;
  }
}

与“循环”加载平衡不同,ip_hash意味着对于任何给定的IP地址,NGINX将始终转发到同一个应用程序实例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM