首页 > 解决方案 > Haproxy 设置相同会话 cookie 依赖于用户代理

问题描述

在 haproxy 中,我需要能够根据用户代理为 cookie 设置相同的站点,因为某些旧版本的 chrome 不支持此标志,然后我需要删除。

我已经尝试了以下配置,但它并不想工作:

        acl old_chrome capture.req.hdr(User-Agent) ^.+Chrome\/(((5[1-9])|6[0-6]))\..+$
        http-response replace-header Set-Cookie: SERVERID; SameSite=None if !old_chrome

有什么建议吗?

标签: aclhaproxy

解决方案


我已经使它与以下配置一起工作:

declare capture request len 40000
http-request capture req.fhdr(User-Agent) len 64
http-response replace-header Set-Cookie (JSESSIONID=[^;]*);(.*) \1;\ Path=/;\ Secure;\ HttpOnly;\ SameSite=None if !{ capture.req.hdr(1) -i -m reg ^.+Chrome\/(((5[1-9])|6[0-6]))\..+$ }

推荐阅读