Squid cache(简称为Squid)是一个流行的自由软件,它符合GNU通用公共许可证。Squid作为网页服务器的前置cache服务器,可以代理用户向web服务器请求数据并进行缓存,也可以用在局域网中,使局域网用户通过代理上网。Squid主要设计用于在Linux一类系统运行。1.squid代理:
yum install squid #安装的是squid3.x版的
vi /etc/squid/squid.conf
添加如下(注意顺序,尽量排在顶端)acl localnet src 192.168.1.0/32 #定义你的源本地网段或者IP acl dst_net dst 8.8.8.8 #定义代理可以访问的目标IP、域名、网段http_access allow localnet #允许localnet 定义的源可以通过代理访问
http_access deny !dst_net #拒绝访问 不是dst_net定义的目标地址,即只能访问dst_net
#http_port =3128 默认监听端口3128 ,#http_access默认拒绝所有,即没有匹配到任何一项,就拒绝然后在你的客户IE设置代理IP和端口,如下图:xxxxxx
2.squid反向代理:vi /etc/squid/squid.conf
添加acl和http_access 允许所有访问
在http_port=80 设置监听端口80,然后在下面添加
cache_peer 192.168.1.156 parent 8000 0 name=a #设置多个后台IP和端口,另加一行
cache_peer_domain a #多个域名空格隔开
出现下面错误:
ERROR
The requested URL could not be retrieved
The following error was encountered while trying to retrieve the URL:
Invalid URL
Some aspect of the requested URL is incorrect.
Some possible problems are:
Missing or incorrect access protocol (should be
http://
or similar)Missing hostname
Illegal double-escape in the URL-Path
Illegal character in hostname; underscores are not allowed.
Your cache administrator is .
出现上面的错误,需要修改下:
http_port 80 defaultsite=www.kkk.com
cache_peer 192.168.1.156 parent 8000 0 no-query originserver weight=1 name=a
cache_peer_domain a
或者:(推荐)
http_port 80 transparent
cache_peer 192.168.1.156 parent 8000 0 no-query originserver name=a
cache_peer 192.168.1.144 parent 80 0 no-query originserver name=b
cache_peer_domain a www.kkk.com
cache_peer_domain b www.df.com
然后重新访问正常2.反向代理
Access Denied Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.这样的错误,需要在客户端取消代理,即:不使用任何代理,解决参考文献:http://blog.chinaunix.net/uid-20489809-id-1665891.html