原文位址:http://blog.sina.com.cn/s/blog_67dd1efa0100izc0.html
squid常用指令:
/usr/local/squid/sbin/squid -z 初始化緩存空間
/usr/local/squid/sbin/squid 啟動
/usr/local/squid/sbin/squid -k shutdown 停止
/usr/local/squid/sbin/squid -k reconfigure 重新載入配置檔案
/usr/local/squid/sbin/squid -k rotate 輪循日志
#acl all src 0.0.0.0/0.0.0.0 and http_access allow all選項定義了一個通路控制清單。詳細情況參見和Squid軟體
#攜帶的文檔。這裡的通路控制清單允許所有對代理服務的通路,因為這裡該代理是加速web伺服器。
acl all src 0.0.0.0/0.0.0.0 #允許所有IP通路
acl manager proto http #manager url協定為http
acl localhost src 127.0.0.1/255.255.255.255 #允午本機IP
acl to_localhost dst 127.0.0.1 #允午目的位址為本機IP
acl Safe_ports port 80 # 允許安全更新的端口為80
acl CONNECT method CONNECT #請求方法以CONNECT
http_access allow all #允許所有人使用該代理.因為這裡是代理加速web伺服器
http_reply_access allow all #允許所有用戶端使用該代理
acl OverConnLimit maxconn 16 #限制每個IP最大允許16個連接配接,防止攻擊
http_access deny OverConnLimit
icp_access deny all #禁止從鄰居伺服器緩沖内發送和接收ICP請求.
miss_access allow all #允許直接更新請求
ident_lookup_access deny all #禁止lookup檢查DNS
http_port 8080 transparent #指定Squid監聽浏覽器客戶請求的端口号。
hierarchy_stoplist cgi-bin ? #用來強制某些特定的對象不被緩存,主要是處于安全的目的。
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
cache_mem 1 GB #這是一個優化選項,增加該記憶體值有利于緩存。應該注意的是:
#一般來說如果系統有記憶體,設定該值為(n/)3M。現在是3G 是以這裡1G
fqdncache_size 1024 #FQDN 高速緩存大小
maximum_object_size_in_memory 2 MB #允許最大的檔案載入記憶體
memory_replacement_policy heap LFUDA #動态使用最小的,移出記憶體cache
cache_replacement_policy heap LFUDA #動态使用最小的,移出硬碟cache
cache_dir ufs /home/cache 5000 32 512 #高速緩存目錄 ufs 類型使用的緩沖值最大允午1000MB空間,
#32個一級目錄,512個二級目錄
max_open_disk_fds 0 #允許最大打開檔案數量,0 無限制
minimum_object_size 1 KB #允午最小檔案請求體大小
maximum_object_size 20 MB #允午最大檔案請求體大小
cache_swap_low 90 #最小允許使用swap 90%
cache_swap_high 95 #最多允許使用swap 95%
ipcache_size 2048 # IP 位址高速緩存大小 2M
ipcache_low 90 #最小允許ipcache使用swap 90%
ipcache_high 95 #最大允許ipcache使用swap 90%
access_log /var/log/squid/access.log squid #定義日志存放記錄
cache_log /var/log/squid/cache.log squid
cache_store_log none #禁止store日志
emulate_httpd_log on #将使Squid仿照Web伺服器的格式建立通路記錄。如果希望使用
#Web通路記錄分析程式,就需要設定這個參數。
refresh_pattern . 0 20% 4320 override-expire override-lastmod reload-into-ims ignore-reload #更新cache規則
acl buggy_server url_regex ^http://.... http:// #隻允許http的請求
broken_posts allow buggy_server
acl apache rep_header Server ^Apache #允許apache的編碼
broken_vary_encoding allow apache
request_entities off #禁止非http的标分準請求,防止攻擊
header_access header allow all #允許所有的http報頭
relaxed_header_parser on #不嚴格分析http報頭.
client_lifetime 120 minute #最大客戶連接配接時間 120分鐘
cache_mgr [email protected] #指定當緩沖出現問題時向緩沖管理者發送告警資訊的位址資訊。
cache_effective_user squid #這裡以使用者squid的身份Squid伺服器
cache_effective_group squid
icp_port 0 #指定Squid從鄰居伺服器緩沖内發送和接收ICP請求的端口号。
#這裡設定為0是因為這裡配置Squid為内部Web伺服器的加速器,
#是以不需要使用鄰居伺服器的緩沖。0是禁用
# cache_peer 設定允許更新緩存的主機,因是本機是以127.0.0.1
cache_peer 127.0.0.1 parent 80 0 no-query default multicast-responder no-netdb-exchange
cache_peer_domain 127.0.0.1
hostname_aliases 127.0.0.1
error_directory /usr/share/squid/errors/Simplify_Chinese #定義錯誤路徑
always_direct allow all # cache丢失或不存在是允許所有請求直接轉發到原始伺服器
ignore_unknown_nameservers on #開反DNS查詢,當域名位址不相同時候,禁止通路
coredump_dir /var/log/squid #定義dump的目錄
max_filedesc 2048 #最大打開的檔案描述
half_closed_clients off #使Squid在當read不再傳回資料時立即關閉用戶端的連接配接。
#有時read不再傳回資料是由于某些客戶關閉TCP的發送資料
#而仍然保持接收資料。而Squid分辨不出TCP半關閉和完全關閉。
buffered_logs on #若打開選項“buffered_logs”可以稍稍提高加速某些對日志檔案的寫入,該選項主要是實作優化特性。
#防止天涯盜鍊,轉嫁給百度
acl tianya referer_regex -i tianya
http_access deny tianya
deny_info tianya
#阻止baidu蜘蛛
acl baidu req_header User-Agent Baiduspider
http_access deny baidu
#限制同一IP用戶端的最大連接配接數
acl OverConnLimit maxconn 128
#防止被人利用為HTTP代理,設定允許通路的IP位址
acl myip dst 222.18.63.37
http_access deny !myip
#允許本地管理
acl Manager proto cache_object
acl Localhost src 127.0.0.1 222.18.63.37
http_access allow Manager Localhost
cachemgr_passwd 53034338 all
http_access deny Manager
#僅僅允許80端口的代理
acl all src 0.0.0.0/0.0.0.0
acl Safe_ports port 80 # http
http_access deny !Safe_ports
http_access allow all
#Squid資訊設定
visible_hostname happy.swjtu.edu.cn
cache_mgr [email protected]
#基本設定
cache_effective_user squid
tcp_recv_bufsize 65535 bytes
#2.6的反向代理加速配置
cache_peer 127.0.0.1 parent 80 0 no-query originserver
#錯誤文檔
error_directory /usr/local/squid/share/errors/Simplify_Chinese
#單台使用,不使用該功能
icp_port 0
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \? .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
acl apache rep_header Server ^Apache
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
cache_store_log none
pid_filename /usr/local/squid/var/logs/squid.pid
emulate_httpd_log on
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
cache_log /usr/local/squid/var/logs/cache.log
access_log /usr/local/squid/var/logs/access.log combined
coredump_dir /usr/local/squid/var/cache
cache_dir ufs /usr/local/squid/var/cache 10000 16 256
dns_children 32
hosts_file /etc/hosts
cache_mem 400 MB
cache_swap_low 90
cache_swap_high 95
maximum_object_size 32768 KB
maximum_object_size_in_memory 4096 KB
#防止盜鍊
acl picurl url_regex -i \.bmp$ \.png$ \.jpg$ \.gif$ \.jpeg$
acl mystie1 referer_regex -i happy.swjtu.edu.cn
http_access allow mystie1 picurl
acl nullref referer_regex -i ^$
http_access allow nullref
acl hasref referer_regex -i .+
http_access deny hasref picur
另一篇關于squid的文章:
《squid - cache_peer和cache_peer_domain詳解》