通过ACL规则可以完成以下两种主要功能:
1、通过设置ACL规则来检查客户端请求是否符合规则,将不符合规则要求的请求直接中断;
2、符合ACL规则的请求由backend指定的后端服务器池执行基于ACL规则的负载均衡,不符合的可以交由其它服务器池执行。
Haproxy中的ACL汇总设置在frontend部分
语法:
acl 名称 方法 -i [匹配的路径或文件]
-i:忽略大小写
常用的方法(首部字段和url):
hdr_dom(host):
请求的host名称,如www.yinzhengjie.org.cn
hdr_beg(host):
请求的host开头,如www. img. video. download. ftp.
hdr_end(host):
请求的host结尾,如.com .net .cn
path_beg:
请求的URL开头,如/static、/images、/img、/css
path_end:
请求的URL中资源的结尾,如.gif .png .css .js .jpg .jpeg
url_sub:表示请求url中包含什么字符串
url_dir:表示请求url中存在哪些字符串作为部分地址路径
url_reg: url正则表达式匹配(^前 $后)acl html url_reg -i \.html$
**注意:\.html$ 不等同 .html**
#访问测试:http://www.yinzhengjie.org.cn/static/xxxxxx.gif
引用acl匹配规则
#引用acl匹配规则
use_backend static_pool if url_static or host_static
use_backend php_pool if url_php
use_backend tomcat_pool if url_jsp