参考:https://socket.io/docs/v4/troubleshooting-connection-issues/#a-proxy-in-front-of-your-servers-does-not-accept-the-WebSocket-connection
可能的解释:
服务器前面的代理不接受 WebSocket连接
请在此处查看文档。
在Nginx代理上,修改nginx配置
如下.
http {
server {
listen 80;
server_name example.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}
解决!
如图所示: 下面不再一直出现大量的 https://xxxxxx.com:13001/socket.io/?EIO=4&transport=polling&t=O4ugyw1&sid=Uyh3dEoug6btFfvbAAliy请求.
而是出现类型为websocket的连接,时间那一列显示为待处理.说明此时已启用了websocket长连接.

相关博文
解决socket.io不能使用websocket长连接,一直轮询请求的问题
