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

标签 node.js amazon-web-services nginx socket.io load-balancing

我对此配置有疑问。我的 AWS ELB 接受端口 80 上的 TCP 连接,并使用代理协议(protocol)将它们转发到监听端口 8080 的 nginx 实例。该 nginx Node 应该使用 ip_hash 模块将用户粘到特定 Node 。

这工作得很好,但是 4 个 Node 中只有 2 个被使用,而不是在所有 Node 之间进行负载平衡,这是我的 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 将始终转发到同一个应用程序实例。

关于node.js - AWS ELB -> nginx -> socket.io node.js 粘性负载均衡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36817327/

相关文章:

javascript - 使用 USB 绑定(bind)配置的 Electron 问题?

javascript - 异步获取文件夹中的文件?

amazon-web-services - AWS API 网关 - 私有(private)端点 - 消息被禁止

nginx - 防止NGINX移除端口

php - 带有 nginx 的 Codeigniter 为嵌套应用程序提供 404 错误

node.js - 无法在 docker 机器上安装 npm 模块

javascript - IIS6下运行的Node.js

amazon-web-services - 如何识别 AWS Cloud Formation 模板中逗号分隔列表参数的选择

node.js - 如何在 aws lambda 函数中使用 Socket.io

php - Nginx 在下载时损坏文件