六月学习之Haproxy ACL实践(基于设备调度)
  eHipUjOuzYYH 2023年11月02日 38 0

2、ACL场景实践

2.2、ACL案例-基于设备调度

根据用户请求的User-Agent,调度到不同的后端集群
用户请求Chrome调度到172.16.1.7:80
用户请求Firefox调度到172.16.1.8:80

2.2.1、配置后端节点

#web1:Chrome站点定义
cat /etc/nginx/conf.d/www.qingchen.com.conf
server {
    listen 80;
    server_name www.qingchen.com;
    root /www
    location / {
        index index.html
    }
}
echo "Chrome-->web1" > /www/index.html

#web2:Firefox站点定义
cat /etc/nginx/conf.d/www.qingchen.com.conf
server {
    listen 8080;
    server_name www.qingchen.com;
    root /www
    location / {
        index index.html
    }
}
echo "Firefox-->web2" > /www/index.html

2.2.2、配置Haproxy

frontend web
    bind *:80
    mode http
    
    # acl规则-基于设备调度   chrome --www    firefox -- m
    acl chrome_agent hdr(User-Agent) -m sub -i chrome
    acl firefox_agent hdr(User-Agent) -m sub -i firefox
    
    # 调用
    use_backend www_cluster if chrome_agent
    use_backend blog_cluster if firefox_agent
    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.2.3、客户端测试

curl -A "firefox" -HHost:www.qingchen.net http://10.0.0.5
curl -A "chrome" -HHost:www.qingchen.net http://10.0.0.5
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  P3nxyT0LRuwj   2023年11月28日   26   0   0 nginxhtmlWeb
  38gcbVXUBcLA   2023年11月26日   25   0   0 服务器htmlHTTP
  bYdMetjCLs2g   2023年11月19日   22   0   0 服务器firefox数据
  ApTxpH0CpnLS   2023年11月13日   31   0   0 sedhtmljavaAPI
  ETWZF7L1nsXD   2023年11月13日   29   0   0 nginxhtml
  lHsWkjQSrEp1   2023年11月13日   31   0   0 iosciscohtml