ACL derivatives :
hdr([<name>[,<occ>]]) : exact string match 字符串精确匹配
hdr_beg([<name>[,<occ>]]) : prefix match
hdr_dir([<name>[,<occ>]]) : subdir match
hdr_dom([<name>[,<occ>]]) : domain match
hdr_end([<name>[,<occ>]]) : suffix match
hdr_len([<name>[,<occ>]]) : length match
hdr_reg([<name>[,<occ>]]) : regex match
hdr_sub([<name>[,<occ>]]) : substring match
192.168.32.152 haproxy env-zjtest8
192.168.32.154 frontend env-zjtest8
frontend web_service
bind *:80
acl hmq_6_req hdr(host) -i www.zjtest8.com
use_backend webserver_80 if hmq_6_req
acl hmq_7_req path_beg -i /api
use_backend web_api if hmq_7_req
backend webserver_80
mode http
balance roundrobin
server webhost01_80 192.168.32.154:8001 check inter 2000 fall 3
backend web_api
balance roundrobin
server webhost01_80 192.168.32.101:3000 check inter 2000 fall 3
v-dev-redis01:/var/named# curl www.zjtest8.com 跳转到192.168.32.154:8001
hy test
这个时候访问;http://www.zjtest8.com/api/ipsearch?ip=202.101.172.35 也会跳到nginx服务器
192.168.32.152 - - [11/Sep/2016:16:34:02 +0800] "GET /api/ipsearch?ip=202.101.172.35 HTTP/1.1" 404 168 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0"
haproxy 修改为:
acl hmq_6_req hdr_beg(host) -i www.zjtest8.com
访问 http://www.zjtest8.com/api/ipsearch?ip=202.101.172.35 还是会跳到nginx服务器
加上:
acl hmq_6_req hdr_beg(host) -i www.zjtest8.com
acl url_static_zl path_end .html .gif .png .jpg .css .js
use_backend webserver_80 if hmq_6_req url_static_zl
此时可以请求到/api