我们如何根据Cookie状态将Haproxy配置为基于Cookie的Load-Balacer?即如果cookie不存在则重定向到server1&如果存在cookie然后服务器2?
我搜索了这个然后我得到了ACL,但它是Header,我们可以配置它用于cookie存在吗?
先谢谢。
答案 0 :(得分:0)
以下是我如何检查cookie“fslanguage”的值,并根据语言在请求中设置Accept-Language标头。您可以轻松地执行后端规则(请参阅use_backend)而不是reqrep规则。
acl langCookie_en cook(fslanguage) en
reqrep Accept-Language:\ (.*) Accept-Language:\ en,\1 if langCookie_en
acl langCookie_fr cook(fslanguage) fr
reqrep Accept-Language:\ (.*) Accept-Language:\ fr,\1 if langCookie_fr
acl langCookie_de cook(fslanguage) de
reqrep Accept-Language:\ (.*) Accept-Language:\ de,\1 if langCookie_de
acl langCookie_es cook(fslanguage) es
reqrep Accept-Language:\ (.*) Accept-Language:\ es,\1 if langCookie_es
acl langCookie_pt cook(fslanguage) pt
reqrep Accept-Language:\ (.*) Accept-Language:\ pt,\1 if langCookie_pt
acl langCookie_it cook(fslanguage) it
reqrep Accept-Language:\ (.*) Accept-Language:\ it,\1 if langCookie_it
acl langCookie_ru cook(fslanguage) ru
reqrep Accept-Language:\ (.*) Accept-Language:\ ru,\1 if langCookie_ru
acl langCookie_ja cook(fslanguage) ja
reqrep Accept-Language:\ (.*) Accept-Language:\ ja,\1 if langCookie_ja
acl langCookie_ko cook(fslanguage) ko
reqrep Accept-Language:\ (.*) Accept-Language:\ ko,\1 if langCookie_ko
acl langCookie_zh cook(fslanguage) zh
reqrep Accept-Language:\ (.*) Accept-Language:\ zh,\1 if langCookie_zh