2012-05-11 170 views
14

我使用nginx version: nginx/1.0.12Nginx的TCP(網頁套接字)超時/保持連接配置

我的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/*; 
} 

我的應用程序似乎是下降的WebSocket connnections每75秒(左右)我認爲這是因爲Nginx的默認Keepalive配置。如何增加超時時間?

感謝

+0

查看[wiki](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive)。 –

+0

我以前曾嘗試過:我在第20行添加了keepalive 32(在服務器127.0.0.1:9000下),並且在/usr/local/nginx/conf/nginx.conf中獲得了nginx:[emerg]未知指令「keepalive」: 20 –

+0

@DmitryPaskal,如果我刪除上游指令(我還沒有進行負載平衡)並在服務器標籤中添加代理服務器通行證,那我該怎麼辦? –

回答

26

我想這是不支持的nginx 1.7.1的websocket_*_timeout(它提供了:未知的指令)。

但是設置高proxy_*_timeout作品:

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

7d裝置7天,見official nginx configuration reference

另外,你可能只需要設置proxy_read_timeout 7d;因爲這是一個通常此事,除非後面的服務器代理非常緩慢。

+0

我嘗試了相同的,它工作正常......但在Firebug(爲Firefox添加),它給錯誤說 - 「NetworkError:404 Not Found - http:// localhost/......「和」Firefox無法在ws:// localhost/.....上建立到服務器的連接「 –

+0

'websocket _ * _ timeout'需要使用'nginx_tcp_proxy_module'模塊編譯nginx從https://github.com/yaoweibin/nginx_tcp_proxy_module – isapir

+0

你節省我的一天感謝 – onalbi