如何使用在应用服务器上设置的cookie在haproxy中路由请求?
例: SESS=<hash-of-username>
在任何情况下,haproxy都不应自行插入cookie.
为了测试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)
如果您只想读取请求中的 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)
| 归档时间: |
|
| 查看次数: |
10371 次 |
| 最近记录: |