我正在研究 HAProxy 作为 F5 的可能替代品。F5 能够根据响应标头值持久化会话:
when HTTP_RESPONSE {
set session [HTTP::header X-Session]
if {$session ne ""} {
persist add uie $session
}
}
然后将标头、查询参数、路径等中包含相同会话 ID 的所有后续请求路由到同一台机器,例如:
when HTTP_REQUEST {
set session [findstr [HTTP::path] "/session/" 9 /]
if {$session} {
persist uie $session
}
}
我想知道这是否可以通过 HAProxy 来实现?
答案1
HAProxy 1.5(当前开发版本)通过以下方式实现响应粘性:
stick store-response
命令。命令如下:
stick store-response hdr(X-Session)
stick on url-param(session) # the session ID is in a query parameter
# if the session ID is in the path, like /session/{session ID}/doSomething
# in this case, the X-Session header value probably has to be the format "/session/{session ID}"
# and the session ID length has to be fixed
stick on path {session ID + path prefix length, including slashes} if path_beg "/session"
免责声明:以上内容基于阅读文档,并未在实际的 HAProxy 安装上进行测试。