我正在将 Haproxy 与 Tornado 一起用于 websocket。如果我直接连接到 Tornado,我的连接工作正常,但如果我使用具有以下配置的 HAproxy,则连接在 50 秒后关闭。
我的 Haproxy 配置文件如下。
global
daemon
maxconn 4032
pidfile /var/run/haproxy.pid
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
option http-server-close
maxconn 4032
frontend http-in
bind *:80
acl is_websocket hdr_end(host) -i WebSocket
use_backend servers if is_websocket
default_backend servers
option redispatch
option http-server-close
maxconn 2000
contimeout 500000
clitimeout 500000
srvtimeout 500000
contimeout 500000
timeout contimeout 500000
timeout connect 500000
backend servers
server server1 127.0.0.1:8886 maxconn 4032
现在通过使用上面的配置,我的 websocket 连接在 50 秒后自动丢失。我想做持久连接,那么有什么方法可以使 HAproxy 中的连接持久化?
最佳答案
I changed timeout connect 0ms, timeout client 0ms, timeout server 0ms in defaults section then my connection is persistent connection because if i give value 0 then it will be infinite connection timeout value.
您不应该这样做,因为这些选项也适用于通常的 HTTP 流量。
将超时连接/客户端/服务器设置为适当的值并使用
timeout tunnel
用于网络套接字。The tunnel timeout applies when a bidirectional connection is established between a client and a server, and the connection remains inactive in both directions. This timeout supersedes both the client and server timeouts once the connection becomes a tunnel.
(见:http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#timeout%20tunnel)
关于websocket - 在 HAproxy 中,我的 websocket 连接在 50 秒后关闭。如何改变它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15633046/