haproxy动静分离的验证

线上出现过项目的静态文件被拦截,不能直接访问。所以想到了haproxy指向对应的url来访问静态文件,想到这里在网络搜索了下,确实有此功能。立即上测试环境验证下:

在listen中增加两行:

​ #定义当请求的内容是对应的文件时,将请求转交给static server的acl规则

​ acl url_static path_end -i index.xml

​ #引用acl匹配规则

​ use_backend static_pool if url_static

​ backend static_pool
​ option httpchk GET /index.xml
​ server static1 10.0.0.10:80 cookie A check port 80 inter 1000 fall 1

相同的外部访问域名和端口,根据指定的规则,去到不同的服务器(静态和动态服务器)。

重载配置,service haproxy reload。

原文地址:https://www.cnblogs.com/fishsky/p/10826032.html