Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了node.js – 具有nginx负载均衡器问题的Socket.IO集群大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在运行Nginx作为Socket.IO服务器的反向代理,该服务器负载平衡多个集群进程的请求.每个集群进程都被告知要侦听不同的端口.

Nginx服务器配置为基于IP哈希加载平衡,但我收到消息:

ws:// {domain} /socket.io/?EIO=3\u0026amp;transport=websocket\u0026amp;sid=KaU3C8caGVK4gU1LAAAB失败:WebSocket在建立连接之前关闭.

我的Nginx配置有:

http {
    {+ default configs}

    upstream io_nodes {
        ip_hash;
        server 127.0.0.1:3000;
        server 127.0.0.1:3001;
        server 127.0.0.1:3002;
        server 127.0.0.1:3003;
    }

}

认vhost:

server {
#listen   80; ## listen for ipv4; this line is default and implied
#listen   [::]:80 default ipv6only=on; ## listen for ipv6

root /usr/share/Nginx/www/static/web;
index index.html index.htm;

# Make site accessible from http://localhost/
server_name {domain};

LOCATIOn / {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-ForWARDed-For $proxy_add_x_forWARDed_for;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_pass http://io_nodes;
     }
}

任何帮助,将不胜感激.如果我在没有集群的情况下运行nodejs服务器,它的行为正确,我在此设置中使用的引用位于:http://socket.io/docs/using-multiple-nodes/.

谢谢

解决方法

发现问题是安装的Nginx版本是< 1.3并没有支持websockets. 对于其他任何人,您可以查看如何在ubuntu上安装更新版本的Nginxhttp://usefulmix.com/install-upgrade-to-latest-nginx-without-compiling-from-source/
@H_489_33@

大佬总结

以上是大佬教程为你收集整理的node.js – 具有nginx负载均衡器问题的Socket.IO集群全部内容,希望文章能够帮你解决node.js – 具有nginx负载均衡器问题的Socket.IO集群所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。