笺注:以下实验是在 Squid反向代理+轮询(一) 的基础上做的。
目的:
根据不同主机名,通过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 80 0 originserver name=web1
cache_peer_domain web1 www.zhuohua.store
cache_peer 192.168.168.135 parent 88 0 originserver name=web2
cache_peer_domain web2 blog.zhuohua.store blog.zhuohua2.store
保存文件后,重启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)
客户端会一直停留在web1,相当稳定;这种模式适合一般的Web访问。
客户端访问 blog.zhuohua.store、blog.zhuohua2.store等于访问
web2(192.168.168.135:88)
备注:假如web2(192.168.168.135:88)不能被访问时,是会直接看到如下页面内容;就算做了缓存,也不会看到缓存文件的内容的。
#######
修改错误页面中的主机名和管理员联系方式:
修改squid 的主配置文件
[root@localhost ~]# vi /etc/squid/squid.conf
插入:
visible_hostname zhuohua-server
cache_mgr zhuohua@qq.com
保存文件后,重启squid服务:
service squid restart
效果:
|