HAProxy:可能由响应标头触发的会话粘性?

zol*_*oli 5 load-balancing haproxy f5-big-ip sticky-sessions

我正在研究 HAProxy 作为 F5 的可能替代品。F5 能够根据响应标头值持久化会话:

when HTTP_RESPONSE {
  set session [HTTP::header X-Session]
  if {$session ne ""} {
    persist add uie $session
  }
}
Run Code Online (Sandbox Code Playgroud)

然后将所有在标头、查询参数、路径等中包含相同会话 ID 的后续请求路由到同一台机器,例如:

when HTTP_REQUEST {
  set session [findstr [HTTP::path] "/session/" 9 /]
  if {$session} {
    persist uie $session
  }
}
Run Code Online (Sandbox Code Playgroud)

我想知道这是否可以与 HAProxy 一起使用?

zol*_*oli 3

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"
Run Code Online (Sandbox Code Playgroud)

免责声明:以上内容基于阅读文档,未在实际的 HAProxy 安装上进行测试。