Nginx TCP(WebSockets)超时/Keepalive配置 [英] Nginx TCP (WebSockets) Timeout / Keepalive Config

查看:1309
本文介绍了Nginx TCP(WebSockets)超时/Keepalive配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nginx version: nginx/1.0.12

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

My nginx.conf looks like this:

#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秒(或大约75秒)就丢弃一次websocket连接,这是因为Nginx的默认keepalive配置.如何增加超时时间?

My application seems to be dropping websocket connnections every 75 sec (or so) which I think is because of Nginx's default keepalive config. How do increase the timeout?

推荐答案

我尝试了nginx 1.7.1不支持的websocket_*_timeout(它给出了 unknown指令).

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

但是设置较高的proxy_*_timeout可以起作用:

However setting a high proxy_*_timeout works:

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

7d表示7天,请参见官方Nginx配置参考

另外,您可能只需要设置proxy_read_timeout 7d;,因为除非代理后面的服务器非常慢,否则这通常很重要.

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.

这篇关于Nginx TCP(WebSockets)超时/Keepalive配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆