33

我在用nginx version: nginx/1.0.12

我的 nginx.conf 看起来像这样:

#user  nobody;
worker_processes  1;  

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

tcp {

     upstream websockets {
      ## Play! WS location
       server 127.0.0.1:9000;
       check interval=3000 rise=2 fall=5 timeout=1000;
     }    

    server {
        listen 80; 
        listen 8000;
        server_name socket.domain.com;

        tcp_nodelay on; 
        proxy_pass websockets;
        proxy_send_timeout 300;

    }   

     # virtual hosting
     #include /usr/local/nginx/vhosts/*;
}

我的应用程序似乎每 75 秒(左右)丢弃一次 websocket 连接,我认为这是因为 Nginx 的默认 keepalive 配置。如何增加超时?

4

2 回答 2

62

I tried the websocket_*_timeout which are not supported on nginx 1.7.1 (it gives: unknown directive).

However setting a high proxy_*_timeout works:

proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;

7d means 7 days, see official nginx configuration reference

Additionally you probably only have to set the proxy_read_timeout 7d; as that's the one that usually matter unless the server behind the proxy is very slow.

于 2014-07-24T19:49:47.293 回答
7

这些聪明的家伙有同样的问题并解决了它....

NGINX 反向代理 websocket 并启用 SSL (wss://)?

此外,在该模块的原始存储库中,还有来自模块作者的更多说明。

https://github.com/yaoweibin/nginx_tcp_proxy_module/issues/28

它基本上相当于在 server 指令中添加 websocket_*_timeout 指令:

 server {

     ....

     websocket_connect_timeout ######;
     websocket_send_timeout #####;
     websocket_read_timeout #####;

     ....

         }
于 2012-11-01T23:22:54.677 回答