5

我正在将 Haproxy 与龙卷风一起用于 websocket。如果我直接连接到龙卷风,我的连接工作正常,但如果我使用具有以下配置的 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 中的连接持久化?

4

2 回答 2

8

我在默认部分更改了超时连接 0 毫秒、客户端超时 0 毫秒、服务器超时 0 毫秒,然后我的连接是持久连接,因为如果我给出值 0,那么它将是无限连接超时值。

您不应该这样做,因为这些选项也适用于通常的 HTTP 流量。将超时连接/客户端/服务器设置为适当的值并timeout tunnel用于 websockets。

当客户端和服务器之间建立了双向连接并且连接在两个方向上都保持非活动状态时,将应用隧道超时。一旦连接成为隧道,此超时将取代客户端和服务器超时。

(见:http ://cbonte.github.io/haproxy-dconv/configuration-1.5.html#timeout%20tunnel )

于 2015-09-19T07:26:58.690 回答
2

我找到了答案,

timeout connect 0ms, timeout client 0ms, timeout server 0ms我在部分进行了更改,defaults然后我的连接是持久连接,因为如果我给值 0 那么它将是无限连接超时值。

我的最终工作配置如下,

global
        daemon
        maxconn 4032
        pidfile /var/run/haproxy.pid

    defaults
        mode http
        timeout connect 0ms
        timeout client 0ms
        timeout server 0ms
        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
        timeout client  500000

    backend servers
        server server1 127.0.0.1:8886 maxconn 4032
于 2013-03-26T09:45:00.400 回答