题 HAProxy:响应头可能触发会话粘性吗?


我正在调查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有关?


5
2017-09-08 00:45






答案:


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安装上测试。


3
2017-09-10 20:43