Linux-haproxy动静分离
设备
centos7 10.0.0.27 client 客户端
centos7 10.0.017 haproxy服务器
centos8 10.0.0.8 httpd服务器
centos8 10.0.0.18 httpd服务器
设置启用子配置文件,haproxy服务器
[root@centos7-liyj ~]#mkdir /etc/haproxy/conf.d [root@centos7-liyj ~]#vim /lib/systemd/system/haproxy.service #编辑haproxy.service文件 [root@centos7-liyj ~]#cat /lib/systemd/system/haproxy.service [Unit] Description=HAProxy Load Balancer After=syslog.target network.target [Service] ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf.d/ -c -q #添加子配置文件路径 ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf.d/ -p /var/lib/haproxy/haproxy.pid ExecReload=/bin/kill -USR2 $MAINPID LimitNOFILE=100000 [Install] WantedBy=multi-user.target [root@centos7-liyj ~]#systemctl daemon-reload [root@centos7-liyj ~]#systemctl restart haproxy
haproxy服务器子配置文件
[root@centos7-liyj ~]#vim /etc/haproxy/conf.d/test.cfg frontend N65_web_https bind 10.0.0.17:80 ###########################acl setting###################### acl acl_static path_beg -i /static /images /javascript #定义acl acl acl_static path_end -i .jpg .jpeg .png .gif .css .js .html .htm acl acl_app path_beg -i /api ###########################acl hosts###################### #use_backend N65_webserver use_backend static_hosts if acl_static #判断acl匹配为静态资源,调用 static_hosts服务器组 default_backend app_hosts #所有acl不匹配,则使用默认的backend backend static_hosts server 10.0.0.8 10.0.0.8:80 check backend app_hosts server 10.0.0.18 10.0.0.18:80 check #backend N65_webserver # server 10.0.0.8 10.0.0.8:80 # server 10.0.0.18 10.0.0.18:80
测试调度
[root@centos7-liyj ~]#curl www.lyj.org #纯域名,直接调度到18 10.0.0.18 [root@centos7-liyj ~]#curl www.lyj.org 10.0.0.18[root@centos7-liyj ~]#curl www.lyj.org/index.html #域名后加了 .html文件,调度到8 10.0.0.8 [root@centos7-liyj ~]#curl www.lyj.org/index.html 10.0.0.8
分类:
实战案例
, 反向代理HAproxy
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)