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選項定義了一個訪問控制列表。詳細(xì)情況參見和Squid軟件
#攜帶的文檔。這里的訪問控制列表允許所有對代理服務(wù)的訪問,因為這里該代理是加速web服務(wù)器。
acl all src 0.0.0.0/0.0.0.0 #允許所有IP訪問
acl manager proto http #manager url協(xié)議為http
acl localhost src 127.0.0.1/255.255.255.255 #允午本機(jī)IP
acl to_localhost dst 127.0.0.1 #允午目的地址為本機(jī)IP
acl Safe_ports port 80 # 允許安全更新的端口為80
acl CONNECT method CONNECT #請求方法以CONNECT
http_access allow all #允許所有人使用該代理.因為這里是代理加速web服務(wù)器
http_reply_access allow all #允許所有客戶端使用該代理 acl OverConnLimit maxconn 16 #限制每個IP最大允許16個連接,防止攻擊
http_access deny OverConnLimit icp_access deny all #禁止從鄰居服務(wù)器緩沖內(nèi)發(fā)送和接收ICP請求.
miss_access allow all #允許直接更新請求
ident_lookup_access deny all #禁止lookup檢查DNS
http_port 8080 transparent #指定Squid監(jiān)聽瀏覽器客戶請求的端口號。 hierarchy_stoplist cgi-bin ? #用來強(qiáng)制某些特定的對象不被緩存,主要是處于安全的目的。
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY cache_mem 1 GB #這是一個優(yōu)化選項,增加該內(nèi)存值有利于緩存。應(yīng)該注意的是:
#一般來說如果系統(tǒng)有內(nèi)存,設(shè)置該值為(n/)3M。現(xiàn)在是3G 所以這里1G
fqdncache_size 1024 #FQDN 高速緩存大小
maximum_object_size_in_memory 2 MB #允許最大的文件載入內(nèi)存 memory_replacement_policy heap LFUDA #動態(tài)使用最小的,移出內(nèi)存cache
cache_replacement_policy heap LFUDA #動態(tài)使用最小的,移出硬盤cache cache_dir ufs /home/cache 5000 32 512 #高速緩存目錄 ufs 類型使用的緩沖值最大允午1000MB空間,
#32個一級目錄,512個二級目錄 max_open_disk_fds 0 #允許最大打開文件數(shù)量,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服務(wù)器的格式創(chuàng)建訪問記錄。如果希望使用
#Web訪問記錄分析程序,就需要設(shè)置這個參數(shù)。 refresh_pattern . 0 20% 4320 override-expire override-lastmod reload-into-ims ignore-reload #更新cache規(guī)則 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的標(biāo)分準(zhǔn)請求,防止攻擊
header_access header allow all #允許所有的http報頭
relaxed_header_parser on #不嚴(yán)格分析http報頭.
client_lifetime 120 minute #最大客戶連接時間 120分鐘 cache_mgr sky@test.com #指定當(dāng)緩沖出現(xiàn)問題時向緩沖管理者發(fā)送告警信息的地址信息。 cache_effective_user squid #這里以用戶squid的身份Squid服務(wù)器
cache_effective_group squid icp_port 0 #指定Squid從鄰居服務(wù)器緩沖內(nèi)發(fā)送和接收ICP請求的端口號。
#這里設(shè)置為0是因為這里配置Squid為內(nèi)部Web服務(wù)器的加速器,
#所以不需要使用鄰居服務(wù)器的緩沖。0是禁用 # cache_peer 設(shè)置允許更新緩存的主機(jī),因是本機(jī)所以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丟失或不存在是允許所有請求直接轉(zhuǎn)發(fā)到原始服務(wù)器
ignore_unknown_nameservers on #開反DNS查詢,當(dāng)域名地址不相同時候,禁止訪問
coredump_dir /var/log/squid #定義dump的目錄 max_filedesc 2048 #最大打開的文件描述 half_closed_clients off #使Squid在當(dāng)read不再返回數(shù)據(jù)時立即關(guān)閉客戶端的連接。
#有時read不再返回數(shù)據(jù)是由于某些客戶關(guān)閉TCP的發(fā)送數(shù)據(jù)
#而仍然保持接收數(shù)據(jù)。而Squid分辨不出TCP半關(guān)閉和完全關(guān)閉。 buffered_logs on #若打開選項“buffered_logs”可以稍稍提高加速某些對日志文件的寫入,該選項主要是實現(xiàn)優(yōu)化特性。 #防止天涯盜鏈,轉(zhuǎn)嫁給百度
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客戶端的最大連接數(shù)
acl OverConnLimit maxconn 128
http_access deny OverConnLimit #防止被人利用為HTTP代理,設(shè)置允許訪問的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信息設(shè)置
visible_hostname happy.swjtu.edu.cn
cache_mgr ooopic2008@qq.com #基本設(shè)置
cache_effective_user squid
cache_effective_group 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
cache deny QUERY acl apache rep_header Server ^Apache
broken_vary_encoding allow 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
emulate_httpd_log on 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 picurl