nginx配置如下:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
#ip_hash;
server 10.50.127.59:3000;
server 10.50.127.60:3000;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://websocket;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
并且即使部署成功后,建立连接非常慢. 用chrom测试,发现连接协议为jsonpolling. 求解,谢谢!
============================分割线================================================
根据实际测试得出.根据官网的配置是确实可行的. 出现这样的原因,是因为服务外网映射的问题和nodejs和socket.io无关. 内网测试正常,外网映射NAT等问题.