use*_*369 5 nginx node.js socket.io
我正在运行NGINX作为Socket.IO服务器的反向代理,该服务器负载平衡多个集群进程的请求.每个集群进程都被告知要侦听不同的端口.
nginx服务器配置为基于IP哈希加载平衡,但我收到消息:
ws://{domain}/socket.io/?EIO=3&transport=websocket&sid=KaU3C8caGVK4gU1LAAAB failed: WebSocket is closed before the connection is established.
我的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;
}
}
Run Code Online (Sandbox Code Playgroud)
默认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;
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.如果我在没有集群的情况下运行nodejs服务器,它的行为正确,我在此设置中使用的引用位于:http://socket.io/docs/using-multiple-nodes/.
谢谢
我发现问题是安装的 nginx 版本 < 1.3 并且没有 websockets 支持。
对于其他人,您可以查看如何在 ubuntu 上安装较新版本的 nginx:
http://usefulmix.com/install-upgrade-to-latest-nginx-without-compiling-from-source/
| 归档时间: |
|
| 查看次数: |
888 次 |
| 最近记录: |