2、ACL场景实践
2.3、ACL案例-基于路径调度
#根据用户请求的URL。调度到不同的后端集群
用户通过/static调度到172.16.1.7:80
用户请求/user调度到172.16.1.8:80
2.3.1、配置后端节点
#web1: /static站点定义
cat /etc/nginx/conf.d/www.qingchen.com.conf
server {
listen 80;
server_name www.qingchen.com;
root /www
location / {
index index.html
}
}
mkdir /www/static
echo "static-->web1" > /www/static/index.html
#web2: /user站点定义
cat /etc/nginx/conf.d/www.qingchen.com.conf
server {
listen 8080;
server_name www.qingchen.com;
root /www
location / {
index index.html
}
}
mkdir /www/user
echo "user-->web1" > /www/user/index.html
2.3.2、配置Haproxy
frontend web
bind *:80
mode http
# acl规则
acl www_site hdr(host) -i www.qingchen.net
# acl规则-请求/static www_cluster /user --- blog_cluster
acl req_static path_beg -i /static
acl req_user path_beg -i /user
# 调用
use_backend www_cluster if www_site req_static
use_backend blog_cluster if www_site req_user
default_backend www_cluster
backend www_cluster
balance roundrobin
option httpchk HEAD / HTTP/1.1\r\nHost:\ www.qingchen.net
server 172.16.1.7 172.16.1.7:80 check port 80 inter 3s rise 2 fall 3
server 172.16.1.8 172.16.1.8:80 check port 80 inter 3s rise 2 fall 3
backend blog_cluster
balance roundrobin
option httpchk HEAD / HTTP/1.1\r\nHost:\ www.qingchen.net
server 172.16.1.7 172.16.1.7:8080 check port 8080 inter 3s rise 2 fall 3
server 172.16.1.8 172.16.1.8:8080 check port 8080 inter 3s rise 2 fall 3
2.3.3、客户端测试
curl -HHost:www.qingchen.net http://10.0.0.5/static
curl -HHost:www.qingchen.net http://10.0.0.5/user
标签:Haproxy,www,qingchen,调度,ACL,static,user,172.16,server
From: https://blog.51cto.com/u_13236892/6769230