3、使用haproxy的ACL实现基于文件后缀名的动静分离
3、使用haproxy的ACL实现基于文件后缀名的动静分离
[root@centos7 haproxy]# vim /etc/haproxy/conf.d/test.cfg
frontend magedu_httpd_port
bind 10.0.0.7:80
mode http
balance roundrobin
log global
option httplog
####################act setting##################################
acl acl_static path_end -i .jpg .jpeg .png .gif .css .js .html
acl acl_php path_end -i .php
#####################act hosts##################################
use_backend mobile_hosts if acl_static
use_backend app_hosts if acl_php
default_backend pc_hosts
###################### backend hosts #############################
backend mobile_hosts
mode http
server web1 10.0.0.17 check inter 2000 fall 3 rise 5
backend pc_hosts
mode http
server web2 10.0.0.27:80 check inter 2000 fall 3 rise 5
backend app_hosts
mode http
server web2 10.0.0.27:80 check inter 2000 fall 3 rise 5
#分别在后端两台主机准备相关文件
[root@centos17 ~]#ls /var/www/html
index.html wang.jpg
[root@centos27 ~]#cat /var/www/html/test.php
<?php
echo "<h1>http://10.0.0.27/test.php</h1>\n";
?>