使用现有cookie进行路由

Eri*_*ner 4 haproxy

如何使用在应用服务器上设置的cookie在haproxy中路由请求?

例: SESS=<hash-of-username>

在任何情况下,haproxy都不应自行插入cookie.

ark*_*kod 8

为了测试haproxy背后的特定服务器,我可以推荐这种方法:

frontend http
   acl is_cookie_hack_1 hdr_sub(cookie) server_test_hack=server1
   acl is_cookie_hack_2 hdr_sub(cookie) server_test_hack=server2
   ... insert your normal acl rules here

   use_backend bk_server_1 if is_cookie_hack_1
   use_backend bk_server_2 if is_cookie_hack_2
   ... insert your normal use_backend expressions here

backend bk_server_1
   ...

backend bk_server_2
   ...
Run Code Online (Sandbox Code Playgroud)

我通过这个脚本在我的浏览器的js控制台中通过javascript插入server_test_hack cookie:

document.cookie="server_test_hack=server1";
Run Code Online (Sandbox Code Playgroud)


Goo*_*ner 2

如果您只想读取请求中的 cookie 并相应地进行路由,您可以在配置中执行以下操作:

frontend http
   acl cookie_found hdr_sub(cookie) COOKIENAME
   use_backend app_server if cookie_found

backend app_server
   balance roundrobin  
   server channel1 X.X.X.X:PORT #Host1
   server channel2 Y.Y.Y.Y:PORT #Host2
Run Code Online (Sandbox Code Playgroud)

  • 不,它仍然无法使用 **cookie 值** 进行平衡。 (2认同)