haproxy匹配不同路径转发

本文略过haproxy安装和基本配置
主要写一下haproxy根据不同不路径访问不同集群
本文架构如图,集群A和集群B就先用一台web服务器代替

《haproxy匹配不同路径转发》

利用ACL匹配访问路径,访问192.168.0.11/a,和192.168.0.11/b时返回不同集群的内容,配置如下

listen web
bind 192.168.0.11:80
mode http
acl static_path_a path_beg -i /a #path_beg匹配URL开头
use_backend static_path_host_a if static_path_a
acl static_path_b path_beg -i /b
use_backend static_path_host_b if static_path_b

backend static_path_host_a
server web1 192.168.0.109:80

backend static_path_host_b
server web1 192.168.0.105:80

当然实际情况backend中有很多提供相同服务的服务器,我在这分别在102.168.0.109和192.168.0.105搭建两台apache进行测试,在默认目录中创建a,b目录,默认页输入不同内容,效果如图

《haproxy匹配不同路径转发》

《haproxy匹配不同路径转发》

    原文作者:转行运维
    原文地址: https://blog.51cto.com/12107094/2488875
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞