Squid.conf配置文件詳解

原文地址: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_access deny OverConnLimit

#防止被人利用爲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
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 picur


另一篇關於squid的文章:

《squid - cache_peer和cache_peer_domain詳解》


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章