Jos*_*son 10 html5 haproxy server-sent-events
我正在尝试将端点添加到发送Server Sent Events的现有应用程序.通常可能没有约5分钟的事件.我希望配置该端点不会切断我的服务器,即使响应在~1分钟内没有完成,但是如果服务器无法响应则所有其他端点都会超时.
有没有一种简单的方法来支持HAProxy中的服务器发送事件?
小智 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
Run Code Online (Sandbox Code Playgroud)
在那之前没什么特别的.
现在,还在以下defaults部分:
# handle the situation where a client suddenly disappears from the net
timeout client-fin 30s
Run Code Online (Sandbox Code Playgroud)
接下来,跳转到您的backend定义并添加:
timeout tunnel 10h
Run Code Online (Sandbox Code Playgroud)
我建议高价值,10小时似乎没问题.
您还应该避免使用默认http-keep-alive选项,SSE不会使用它.相反,使用http-server-close.