返回列表 发帖

CentOS8_Squid反向代理+轮询(二)

笺注:以下实验是在 CentOS8_Squid反向代理+轮询(一) 的基础上做的。

目的:
根据不同主机名,通过Squid反向代理到不同IP地址的后台Web服务器

实验要求:(web1、web2都为Linux下的Apache服务器)
客户端在浏览器地址栏中输入www.zhuohua.store,将访问web1(192.168.168.130:80)
客户端在浏览器地址栏中输入bbs.zhuohua.store、blog.zhuohua2.store,将访问web2(192.168.168.135:88)



修改Squid 的主配置文件:
[root@localhost ~]# vi /etc/squid/squid.conf
修改:
cache_peer 192.168.168.130 parent 80 0 originserver name=www.zhuohua.store
acl web1 dstdomain www.zhuohua.store
cache_peer_access www.zhuohua.store allow web1

cache_peer 192.168.168.135 parent 88 0 originserver name=blog.zhuohua2.store
acl web2 dstdomain blog.zhuohua2.store
cache_peer_access blog.zhuohua2.store allow web2

cache_peer 192.168.168.135 parent 88 0 originserver name=bbs.zhuohua.store
acl web3 dstdomain bbs.zhuohua.store
cache_peer_access bbs.zhuohua.store allow web3

图片1.png


保存文件后,重启squid服务:
[root@centos8 ~]# systemctl restart squid


检测Squid的配置有没有问题:
[root@centos8 ~]# squid -k parse
图片2.png
注释:截图有省略。






配置Windows客户端
在没有DNS服务器来解析时,可以在hosts 文件里直接指定
修改C:\Windows\System32\drivers\etc\hosts
追加:(客户端只访问代理服务器)
192.168.168.154 www.zhuohua.store
192.168.168.154 bbs.zhuohua.store blog.zhuohua2.store


客户端访问www.zhuohua.store等于访问web1(192.168.168.130:80)
图片3.png


客户端会一直停留在web1,相当稳定;这种模式适合一般的Web访问。
图片4.png




客户端访问 bbs.zhuohua.store、blog.zhuohua2.store等于访问
192.168.168.135:88

图片5.png

图片6.png

返回列表