Nginx websocket代理在2分钟后断开连接

时间:2016-02-11 18:31:04

标签: nginx proxy websocket

我正在尝试使用nginx 1.9.11将位置代理到websocket上游。这是配置摘录:

upstream autocloud_dispatcher {
  server 127.0.0.1:4000 fail_timeout=0;
}

server {
  .....
  location /ws {
    proxy_pass http://autocloud_dispatcher;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_connect_timeout 7d;
    proxy_send_timeout 7d;
    proxy_read_timeout 7d;
  }
}

除此之外,我每隔90秒从支持发送ping消息。但是连接每2分钟仍然断开连接。 nginx中的其他一些设置默认为120s?

1 个答案:

答案 0 :(得分:2)

以秒为单位设置超时帮助了我,我的配置

location ~ /wss/(.*) {
    proxy_pass http://127.0.0.1:$1;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    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-Forwarded-Proto https;

    proxy_read_timeout  36000s;

    proxy_redirect off;
}