- 论坛徽章:
- 1
|
[操作实例] ACL控制cache_peer做反向WEB加速时虚拟主机对应到不同后端服务器
首先,我们看看squid.conf.default之中的以下基础配置:
第一处:通过ACL之中有关于dstdomain的规则,也就是检查请求网址的域名
- # acl aclname dstdomain .foo.com ... # Destination server from URL
复制代码
第二处:cache_peer_access用来设置对应的cache_peer的访问权限
- # TAG: cache_peer_access
- # Similar to 'cache_peer_domain' but provides more flexibility by
- # using ACL elements.
- #
- # cache_peer_access cache-host allow|deny [!]aclname ...
- #
- # The syntax is identical to 'http_access' and the other lists of
- # ACL elements. See the comments for 'http_access' below, or
- # the Squid FAQ (http://www.squid-cache.org/FAQ/FAQ-10.html).
复制代码
第三处:cache_peer_domain设置对应的cache_peer接受的域名
- # TAG: cache_peer_domain
- # Use to limit the domains for which a neighbor cache will be
- # queried. Usage:
- #
- # cache_peer_domain cache-host domain [domain ...]
- # cache_peer_domain cache-host !domain
- #
- # For example, specifying
- #
- # cache_peer_domain parent.foo.net .edu
- #
- # has the effect such that UDP query packets are sent to
- # 'bigserver' only when the requested object exists on a
- # server in the .edu domain. Prefixing the domain name
- # with '!' means the cache will be queried for objects
- # NOT in that domain.
- #
- # NOTE: * Any number of domains may be given for a cache-host,
- # either on the same or separate lines.
- # * When multiple domains are given for a particular
- # cache-host, the first matched domain is applied.
- # * Cache hosts with no domain restrictions are queried
- # for all requests.
- # * There are no defaults.
- # * There is also a 'cache_peer_access' tag in the ACL
- # section.
- #
复制代码
下面,我们就测试几个例子,看看结果如何。
测试之前,需要做一点点的设置:
- 把www.baidu.com和www.sohu.com域名都指向测试squid服务器的ip。
- *nix设置/etc/hosts,Windows设置系统目录/system32/drivers/etc/hosts
- 我的测试服务器ip是192.168.1.103,squid端口1080
复制代码
squid基本配置如下:
- http_port 192.168.1.103:1080 vhost vport defaultsite=www.test.com
- acl baidu dstdomain www.baidu.com
- acl sohu dstdomain www.sohu.com
- cache_peer www.baidu.com parent 80 0 no-query originserver no-digest
- cache_peer www.sohu.com parent 80 0 no-query originserver no-digest
复制代码
第一次测试规则配置:
- cache_peer_access www.baidu.com deny !baidu
- cache_peer_access www.sohu.com deny !sohu
复制代码
测试网址:http://www.baidu.com:1080 http://www.sohu.com:1080
测试结果:两者均可正确访问
第二次测试规则配置:
- cache_peer_domain www.baidu.com .baidu.com
- cache_peer_domain www.sohu.com .sohu.com
复制代码
测试网址:http://www.baidu.com:1080 http://www.sohu.com:1080
测试结果:两者均可正确访问
第三次测试规则配置:
- cache_peer_access www.baidu.com deny baidu
- cache_peer_access www.sohu.com deny sohu
复制代码
测试网址:http://www.baidu.com:1080 http://www.sohu.com:1080
测试结果:访问baidu的是sohu的squid提示页面,不允许盗用;而访问sohu实际上被我们反向到了baidu的服务器,baidu的可能没有使用squid,所以可以直接访问。
第四次测试规则配置:
- cache_peer_access www.baidu.com deny baidu
- cache_peer_access www.sohu.com deny sohu
复制代码
测试网址:http://www.baidu.com:1080 http://www.sohu.com:1080
测试结果:与第三次测试。
总结,使用cache_peer_access和cache_peer_domain,都可以用来设置cache_peer的存取权限,使得不同的虚拟主机对应不同的后端服务器。
注意:
1. 测试过程之中,配置正确且适合需要时,可能网页上部分图片不可显示,因为试用了绝对网址,而我们的测试端口为1080。所以域名指向我们的服务器的ip,但是80端口没有监听。如果你把测试端口修改为80,则不会出现这样子的事情。
2. 以上只是贴出了测是部分的配置,其他配置请自行设置。 |
|