blog.zhuohua.store's Archiver

admin 发表于 2019-9-9 22:32

Squid反向代理+轮询(二)

笺注:以下实验是在 [url=http://blog.zhuohua.store/viewthread.php?tid=68&extra=page%3D1]Squid反向代理+轮询(一)[/url] 的基础上做的。

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

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


修改Squid 的主配置文件:
[root@localhost ~]# vi /etc/squid/squid.conf
修改:
cache_peer 192.168.168.154 parent [color=Red]80[/color] 0 originserver name=[color=Purple]web1[/color]
cache_peer_domain [color=Purple]web1[/color] www.zhuohua.store

cache_peer 192.168.168.135 parent [color=Red]88[/color] 0 originserver name=[color=Purple]web2[/color]
cache_peer_domain [color=Purple]web2[/color] blog.zhuohua.store blog.zhuohua2.store
[attach]6869[/attach]


保存文件后,重启squid服务:
service squid restart










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



客户端访问www.zhuohua.store等于访问web1(192.168.168.154:80)
[attach]6870[/attach]


客户端会一直停留在web1,相当稳定;这种模式适合一般的Web访问。
[attach]6871[/attach]




客户端访问 blog.zhuohua.store、blog.zhuohua2.store等于访问
web2(192.168.168.135:88)
[attach]6872[/attach]


[attach]6873[/attach]





备注:假如web2(192.168.168.135:88)不能被访问时,是会直接看到如下页面内容;就算做了缓存,也不会看到缓存文件的内容的。
[attach]6874[/attach]













#######
修改错误页面中的主机名和管理员联系方式:

修改squid 的主配置文件
[root@localhost ~]# vi /etc/squid/squid.conf
插入:
visible_hostname zhuohua-server
cache_mgr zhuohua@qq.com
[attach]6875[/attach]


保存文件后,重启squid服务:
service squid restart



效果:
[attach]6876[/attach]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.