socket.io使用了cluster模块,但每次连接的时候都报{"code":1,"message":"Session ID unknown"} 这个错误,有人知道是什么原因吗?不用cluster没有问题。
6 回复
@alsotang 是的,确实是还有一层nginx,配置如下: map $http_upgrade $connection_upgrade { default upgrade; ‘’ close; }
upstream websocket {
#ip_hash;
server http://127.0.0.1:3000;
}
server
{
listen 80;
server_name chat.domain.dev;
location / {
proxy_pass http://websocket;
#proxy_connect_timeout 60;
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-NginX-Proxy true;
# 下面是关键
proxy_http_version 1.1;
#proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 这是配置webpysessoin丢失的问题
#fastcgi_param SCRIPT_NAME "";
}
}
还需要改别的吗?