如何配置HAProxy以使用服务器发送的事件?

时间:2014-01-29 00:34:50

标签: html5 haproxy server-sent-events

我正在尝试将端点添加到发送Server Sent Events的现有应用程序中。通常可能没有约5分钟的事件。我希望将该端点配置为不切断我的服务器,即使响应在~1min内没有完成,但是如果服务器无法响应则所有其他端点都会超时。

是否有一种简单的方法可以在HAProxy中支持服务器发送的事件?

1 个答案:

答案 0 :(得分:7)

以下是我对HAProxy和SSE的建议:你在HAProxy中有很多自定义超时选项,有两个有趣的选项。

timeout tunnel指定隧道连接的超时 - 用于Websockets,SSE或CONNECT。绕过服务器和客户端超时。

timeout client处理客户端失去连接的情况(网络丢失,在结束会话的ACK之前消失等等)

haproxy.cfg中,这是您应该做的事情,首先在defaults部分:

# Set the max time to wait for a connection attempt to a server to succeed
timeout connect 30s
# Set the max allowed time to wait for a complete HTTP request
timeout client  50s
# Set the maximum inactivity time on the server side
timeout server  50s

直到那里没什么特别的。

现在,仍然在defaults部分:

# handle the situation where a client suddenly disappears from the net
timeout client-fin 30s

接下来,跳转到您的backend定义并添加:

timeout tunnel 10h

我建议高价值,10小时似乎没问题。

您还应该避免使用默认的http-keep-alive选项,SSE不会使用它。相反,请使用http-server-close