您的位置:首页 > 运维架构 > 反向代理

Squid安装(Windows)入门实例简介

2014-09-04 22:27 337 查看
转自IT农夫http://blog.csdn.net/kkdelta/article/details/7827950

squid 可以做反向代理将系统中相对静态的页面进行缓存和负责均衡,
提高网站访问速度,增强网站可用性、安全性.
用户访问Squid 反向代理服务器的 IP 地址,这样客户端的 URL 请求将被发送到反向代理服务器。
如果Squid反向代理服务器中缓存了该请求的资源,则将该请求的资源直接返回给客户端,
否则反向代理服务器将向后台的 WEB服务器请求资源,然后将请求的应答返回给客户端,
同时也将该应答缓存在本地,供下一个请求者使用。

其示意图如下:



Windows中安装squid步骤:
1,从http://squid.acmeconsulting.it下载squid windows的安装文件.
也可以从http://download.csdn.net/detail/kkdelta/4474605下载.
下载后解压将squid放在C:\目录下(default),你也可以把Squid放到其他的路径,
但是需要大量的配置squid配置文件中的路径信息。
2,重命名etc文件夹下的文件
squid.conf.default ==> squid.conf
mime.conf.default ==> mime.conf
cachemgr.conf.default ==> cachemgr.conf 
3,简单配置squid.conf,使配置达到如下图的效果



visible_hostname squidhost
#设定squid的主机名,如无此项squid将无法启动
http_port 3128 accel vhost vport
#设定squid为accel加速模式,vhost必须要加.否则将无法将主机头转发至后端服务器,
#访问时就会出现无法找到主机头的错误
cache_peer 147.151.240.234 parent 8080 0 no-query originserver round-robin name=webserver1
cache_peer 147.151.241.151 parent 8080 0 no-query originserver round-robin name=webserver2
cache_peer_domain  webserver1 webserver2 localhost
#将 localhost的请求通过 RR 轮询方式转发到2个父节点中的一个.
#http://localhost:3128的请求将转发到147.151.240.234:8080或者147.151.241.151:8080
acl all src 0.0.0.0/0.0.0.0
http_access allow all

4,启动squid
C:\squid\sbin>squid -z #创建cache目录.
C:\squid\sbin>squid #启动squid

测试:
将147.151.240.234和147.151.241.151的tomcat启动,放上一个test.jsp文件.
在151的机器上的test.jsp输出 The JSP in Tomcat instance 151 
在234的机器上的test.jsp输出 The JSP in Tomcat instance 234
访问http://localhost:3128/xxxweb/test.jsp会轮流输出上面的结果.
对一个jsp的访问每次都会转发到web server上:X-Cache: MISS from
squidhost

[plain] view
plaincopy

[root@Fedora-WLS9-1 bin]# curl -I http://147.151.240.52:3128/examples/jsp/test.jsp  

HTTP/1.0 200 OK  

Server: Apache-Coyote/1.1  

Set-Cookie: JSESSIONID=F3C10D53A916B1852D06687E9E581A2F; Path=/examples  

Content-Type: text/html  

Content-Length: 972  

Date: Fri, 03 Aug 2012 17:51:01 GMT  

X-Cache: MISS from squidhost  

X-Cache-Lookup: MISS from squidhost:3128  

Via: 1.0 squidhost:3128 (squid/2.6.STABLE22)  

Connection: close  

对一个静态的html的访问每次都会转发到web server上:X-Cache: HIT from
squidhost

[plain] view
plaincopy

[root@Fedora-WLS9-1 bin]# curl -I http://147.151.240.52:3128/examples/jsp/test.html  

HTTP/1.0 200 OK  

Server: Apache-Coyote/1.1  

Accept-Ranges: bytes  

ETag: W/"26-1343982480000"  

Last-Modified: Fri, 03 Aug 2012 08:28:00 GMT  

Content-Type: text/html  

Content-Length: 26  

Date: Fri, 03 Aug 2012 17:28:54 GMT  

Age: 195  

<span style="color:#FF0000;"></span>X-Cache: HIT from squidhost  

X-Cache-Lookup: HIT from squidhost:3128  

Via: 1.0 squidhost:3128 (squid/2.6.STABLE22)  

Connection: close  

笔者记录:

重新加载配置文件squid -k reconfigure -n squid
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息