標籤:
squid 可以做反向 Proxy將系統中相對靜態頁面進行緩衝和負責均衡,
提高網站訪問速度,增強網站可用性、安全性.
使用者訪問Squid 反向 Proxy伺服器的 IP 位址,這樣用戶端的 URL 請求將被發送到反向 Proxy伺服器。
如果Squid反向 Proxy伺服器中緩衝了該請求的資源,則將該請求的資源直接返回給用戶端,
否則反向 Proxy伺服器將向背景 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
- [[email protected]dora-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
- [[email protected] 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
Windows Squid 安裝配置