首页 > 解决方案 > acl 的 haproxy 嵌套条件

问题描述

我需要嵌套 ACL 条件

acl route1 hdr_sub(host) -i abc.com hdr_sub(host) -i xyz.com 
acl route2 path_beg /m1
acl route3 path_beg /m2


use backend back1 if route1 (route2 or route3)

// essentially  
route1 AND (route2 OR route3)

匹配后端。与此等效的正确 HA 代码是什么?

标签: haproxy

解决方案


单个 ACL 中的规则是 ORed,因此,您可以将route2androute3规则与此组合:

acl route2 path_beg /m1
acl route2 path_beg /m2

use backend back1 if route1 route2

条件也支持||运算符,但不支持优先级的括号分组,所以a b || c意味着(a and b) or (c),这不等于你想要的......所以如果你不想像上面显示的那样组合 ACL,你需要这个......

use backend back1 if route1 route2 || route1 route3

...这并不完全直观。

或这个:

use backend back1 if route1 route2
use backend back1 if route1 route3

推荐阅读