问题描述
我使用的是 nginx 版本: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 秒(左右)丢弃一次 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
(它给出:未知指令em>).
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 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!