【问题标题】:Socket.io lost connection after few minutes but only with NGINX proxy enabledSocket.io 几分钟后失去连接,但仅启用了 NGINX 代理
【发布时间】:2016-04-06 15:43:44
【问题描述】:

我对 socket.io 有疑问。当我启动我的 Nodejs 应用程序时,套接字正常工作,但几分钟后,与 websocket 的连接关闭,重新连接 Socket.io 后再次发射。

我正在使用 NGINX 代理,我注意到绕过 NGINX 问题解决了,我需要编辑哪个配置?我认为问题在于我的 nginx 配置。

这是我的 NGINX 默认配置:

server { 
listen 80; #listen for all the HTTP requests 
server_name example.com www.example.com; 
return 301 https://www.example.com$request_uri; }


server {
  server_name    example.com;
  listen       443 ssl http2;


#Optimize Webserver work
#client_max_body_size 16M;
keepalive_timeout 20;

ssl on;
ssl_certificate  /root/social/ssl/cert.pem;
ssl_certificate_key /root/social/ssl/key.pem;

  location / {
    proxy_pass http://localhost:5430;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    }

}

upstream io_nodes {
 server 127.0.0.1:5430;
 keepalive 20;
}

请帮忙

【问题讨论】:

    标签: node.js sockets nginx proxy


    【解决方案1】:

    你应该添加另一个参数:

    proxy_read_timeout 96000;
    

    默认值为 60 秒。使用默认值闲置 60 秒后,您将收到“丢失连接”消息。

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-18
      • 2012-05-06
      • 2018-09-20
      • 1970-01-01
      相关资源
      最近更新 更多