免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 13978 | 回复: 10
打印 上一主题 下一主题

[proxy] [操作实例] ACL控制cache_peer做反向WEB加速时虚拟主机对应到不同后端服务器 [复制链接]

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-01-15 16:03 |只看该作者 |正序浏览
[操作实例] ACL控制cache_peer做反向WEB加速时虚拟主机对应到不同后端服务器

  首先,我们看看squid.conf.default之中的以下基础配置:
  第一处:通过ACL之中有关于dstdomain的规则,也就是检查请求网址的域名

  1. #       acl aclname dstdomain   .foo.com ...    # Destination server from URL
复制代码

  第二处:cache_peer_access用来设置对应的cache_peer的访问权限

  1. #  TAG: cache_peer_access
  2. #       Similar to 'cache_peer_domain' but provides more flexibility by
  3. #       using ACL elements.
  4. #        
  5. #       cache_peer_access cache-host allow|deny [!]aclname ...
  6. #         
  7. #       The syntax is identical to 'http_access' and the other lists of
  8. #       ACL elements.  See the comments for 'http_access' below, or
  9. #       the Squid FAQ (http://www.squid-cache.org/FAQ/FAQ-10.html).      
复制代码

  第三处:cache_peer_domain设置对应的cache_peer接受的域名

  1. #  TAG: cache_peer_domain
  2. #       Use to limit the domains for which a neighbor cache will be
  3. #       queried.  Usage:
  4. #  
  5. #       cache_peer_domain cache-host domain [domain ...]
  6. #       cache_peer_domain cache-host !domain
  7. #   
  8. #       For example, specifying
  9. #               
  10. #               cache_peer_domain parent.foo.net        .edu
  11. #        
  12. #       has the effect such that UDP query packets are sent to      
  13. #       'bigserver' only when the requested object exists on a
  14. #       server in the .edu domain.  Prefixing the domain name     
  15. #       with '!' means the cache will be queried for objects   
  16. #       NOT in that domain.
  17. #        
  18. #       NOTE:   * Any number of domains may be given for a cache-host,
  19. #                 either on the same or separate lines.
  20. #               * When multiple domains are given for a particular
  21. #                 cache-host, the first matched domain is applied.
  22. #               * Cache hosts with no domain restrictions are queried
  23. #                 for all requests.
  24. #               * There are no defaults.
  25. #               * There is also a 'cache_peer_access' tag in the ACL
  26. #                 section.
  27. #
复制代码


  下面,我们就测试几个例子,看看结果如何。
  测试之前,需要做一点点的设置:

  1.   把www.baidu.com和www.sohu.com域名都指向测试squid服务器的ip。
  2.   *nix设置/etc/hosts,Windows设置系统目录/system32/drivers/etc/hosts
  3.   我的测试服务器ip是192.168.1.103,squid端口1080
复制代码


  squid基本配置如下:

  1. http_port 192.168.1.103:1080 vhost vport defaultsite=www.test.com
  2. acl baidu dstdomain www.baidu.com
  3. acl sohu  dstdomain www.sohu.com
  4. cache_peer www.baidu.com parent 80 0 no-query originserver no-digest
  5. cache_peer www.sohu.com parent 80 0 no-query originserver no-digest
复制代码


  第一次测试规则配置:

  1. cache_peer_access www.baidu.com deny !baidu
  2. cache_peer_access www.sohu.com deny !sohu
复制代码

  测试网址:http://www.baidu.com:1080 http://www.sohu.com:1080
  测试结果:两者均可正确访问

  第二次测试规则配置:

  1. cache_peer_domain www.baidu.com .baidu.com
  2. cache_peer_domain www.sohu.com .sohu.com
复制代码

  测试网址:http://www.baidu.com:1080 http://www.sohu.com:1080
  测试结果:两者均可正确访问

  第三次测试规则配置:

  1. cache_peer_access www.baidu.com deny baidu
  2. 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,所以可以直接访问。

  第四次测试规则配置:

  1. cache_peer_access www.baidu.com deny baidu
  2. 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. 以上只是贴出了测是部分的配置,其他配置请自行设置。

Snap1.png (66.02 KB, 下载次数: 159)

Snap1.png

论坛徽章:
0
11 [报告]
发表于 2007-11-05 23:20 |只看该作者
怎么启动后提示

The following error was encountered:

Unable to forward this request at this time.
This request could not be forwarded to the origin server or to any parent caches. The most likely cause for this error is that:

The cache administrator does not allow this cache to make direct connections to origin servers, and
All configured parent caches are currently unreachable.

论坛徽章:
0
10 [报告]
发表于 2007-09-13 17:49 |只看该作者
使用hosts不能负载均衡。换DNS可以。

论坛徽章:
0
9 [报告]
发表于 2007-07-31 11:45 |只看该作者
CODE:
  把www.baidu.com和www.sohu.com域名都指向测试squid服务器的ip。
  *nix设置/etc/hosts,Windows设置系统目录/system32/drivers/etc/hosts
  我的测试服务器ip是192.168.1.103,squid端口1080


斑竹,这里的hosts文件应该如何修改?
我想windows的hosts应改成
192.168.1.103     www.baidu.com
192.168.1.103     www.sohu.com

linux的hosts不用这样改吧?

请赐教!谢谢

论坛徽章:
0
8 [报告]
发表于 2007-07-31 10:04 |只看该作者
你PING百度出来的IP ,全部都可以使用IP访问百度的网站

论坛徽章:
0
7 [报告]
发表于 2007-07-30 18:13 |只看该作者
斑竹,您配置里的
cache_peer www.baidu.com parent 80 0 no-query originserver no-digest
可以改成
cache_peer 202.108.22.43 parent 80 0 no-query originserver no-digest
吗?

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
6 [报告]
发表于 2007-01-18 16:02 |只看该作者
原帖由 runco.luo 于 2007-1-18 12:00 发表
真是太好了,谢谢楼主!
如果在hosts文件里一个域名指向多个服务器IP,squid能自动做负载均衡就好了。




这个想法太牛了。

但是不现实。

但是你可以这么做:

ip1 s1.test.com
ip2 s2.test.com
ip3 s3.test.com
ip4 s4.test.com

然后squid用这些。

论坛徽章:
0
5 [报告]
发表于 2007-01-18 12:00 |只看该作者
真是太好了,谢谢楼主!
如果在hosts文件里一个域名指向多个服务器IP,squid能自动做负载均衡就好了。

论坛徽章:
0
4 [报告]
发表于 2007-01-16 09:01 |只看该作者
谢谢,正需要这样的知识,收下慢慢研究了~

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
3 [报告]
发表于 2007-01-15 18:15 |只看该作者
原帖由 zxxz79 于 2007-1-15 16:59 发表
cache_peer_domain www.baidu.com .baidu.com
cache_peer_domain www.sohu.com .sohu.com

个人感觉这个方式比较好用。可以少建一条acl。可以偷懒,配置看起来也清晰


  也可以,不过acl相对来说更加强大一些。
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP