Day: 2022年6月6日

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

参考: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;