上篇文章说了squid的安装
配置文件只贴上现成的,介绍了最基本的前端和后端的项
这里将详细叙述squid的配置文件
1.配置文件squid.conf
# cat /usr/local/squid/etc/squid.conf
http_port 80 accel vhost vport #squid监听的端口,vhost表示根据请求主机头来转发到后端WEB机器,vport 虚拟主机的支持
logfile_rotate 10 #保留最近的10份日志
log_fqdn off #on|off是否记录客户端的完整记录和dns解析等 建议关闭可以减小squid的负担
cache_swap_low 90 #squid通过lru算法将缓存的内容每次都清除到交换空间的这个标准
cache_swap_high 97 #当缓存的内容超过交换空间的这个标准时通过lru算法进行清除缓存内容,清出到cache_swap_low标准
cache_mem 1536 MB #squid可以使用内存的大小
cache_mgr admin #管理员用户
cachemgr_passwd test all #管理员用户的密码
cache_effective_user www #将以这个系统用户运行squid
cache_effective_group www #将以这个系统用户组运行squid
coredump_dir /usr/local/squid/var/cache #缓存目录
cache_dir ufs /usr/local/squid/var/cache 51200 16 256 #缓存目录最大为51200M,这儿的单位是兆字节 和16个1及目录 256个二级目录
cache_replacement_policy lru #清除缓存的规则勇lru规则
memory_replacement_policy lru #清除内存缓存的规则勇lru lru规则和linux的内存管理规则相似,常用的和最新的不清除
cache_store_log none #指定对象存储记录日志的完整路径,包括文件的名称及所在目录,该记录表明哪些对象被写到交换空间,哪些对象被从交换空间清除。
cache_access_log /usr/local/squid/var/logs/accesslog
cache_log /usr/local/squid/var/logs/cachelog #squid的运行日志
ipcache_size 10240 #当一个域名来访问squid服务器时,DNS服务器正解后的IP放入ipcache缓存中,等待squid返回数据时建立连接使用。
fqdncache_size 10240 #当一个IP来访问squid服务器时,DNS服务器反解后的域名将放入fqdncache缓存中,等待squid返回数据时建立连接使用
mime_table /usr/local/squid/etc/mimeconf #该选项用来指定存储squid支持的MIME类型的文件
error_directory /usr/local/squid/share/errors/en-us/ #定义错误日志语言
icon_directory /usr/local/squid/share/icons/ #指明向用户传送错误信息时所用到的图标文件的目录
err_page_stylesheet /usr/local/squid/etc/errorpagecss #错误页面
emulate_httpd_log on #Squid仿照Aapche的日志格式
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh #定义日志格式
max_open_disk_fds 0 #squid打开的文件句柄数
tcp_recv_bufsize 655350 bytes #tcp的缓冲大小
request_header_max_size 5 KB #接收最大的请求头
memory_pools off #的是分配一些内存空间,以备squid 不时之需
memory_pools_limit 64 MB #定义这个内存空间的大小
via off #检查squid请求路由的一个标志,当客户端请求到达第一个代理服务器时,该服务器会在自己发出的请求里面添加 Via 头部,并填上自己的相关信息,当下一个代理服务器 收到第一个代理服务器的请求时,会在自己发出的请求里面复制前一个代理服务器的请求的Via 头部,并把自己的相关信息加到后面,以此类推,当OCS收到最后一个代理服务器的请求时,检查 Via 头部,就知道该请求所经过的路由
maximum_object_size 500 MB #允许缓存的最大文件
minimum_object_size 0 KB #允许缓存的最小文件
maximum_object_size_in_memory 5120 KB #允许在内存中缓存的最大文件
pipeline_prefetch on #可以提升squid处理客户端请求的速度
forwarded_for off #此值控制转发的头X-Forwarded-For
forward_timeout 2 minutes #转发超市时间2分钟
client_lifetime 1 hours #客户端连接超时时间
client_persistent_connections off #因为现在的IE都是多线程,考虑到服务器带宽等网络资源消耗,所以长链接关闭
server_persistent_connections on #服务端长链接是用于在服务器端传递消息时使用已打开的socket链接以节省资源而设置的。
half_closed_clients off #用户请求处于半关闭状态squid会保持这种状态,直到返回套接字的读写错误才将其关闭,这样会浪费系统资源;设置为off,有了这种状态立即关闭请求。
httpd_suppress_version_string on #隐藏服务器信息(比如一些页面拒绝访问,或出现循环)
check_hostnames off #关闭DNS对hostname的检测
visible_hostname CDN.test.net #设置主机明,可以随笔设置
pid_filename /var/run/squidpid #pid文件
vary_ignore_expire off #忽略vary头,课题高缓存额命中率
negative_ttl 0 minutes #一个失败请求的存活时间
reply_header_access Server deny all #隐藏http头的Server项 如下都是
reply_header_access Warning deny all
reply_header_access Expires deny all
reply_header_access Via deny all
reply_header_access Connection deny all
peer_connect_timeout 30 seconds #连接父cache或源站的超时时间
request_timeout 1 minutes #客户端请求超时时间
persistent_request_timeout 2 minutes #持续连接时间(建议和后端WEB服务器或者keepalive一致)
client_lifetime 30 minutes #客户端连接超时时间
half_closed_clients off #用户请求处于半关闭状态squid会保持这种状态,直到返回套接字的读写错误才将其关闭,这样会浪费系统资源;设置为off,有了这种状态立即关闭请求。
pconn_timeout 25 seconds #squid与其他服务器建立连接多久闲置时间关闭连接
shutdown_lifetime 20 seconds #当收到SIGTERM或者SIGHUP信号后,squid将进入一种shutdown pending的模式,等待所有活动的套接字关闭,如果过了这个值,就返回客户端超时。
icp_port 3130 #父子cache或者兄弟cache互相查找使用的
icp_hit_stale off #squid对任何cache住的目标,即使它是陈旧的,都返回ICP_HIT
icp_access allow all #acl运行所有的都访问icp
acl localhost src 127.0.0.1
acl to_localhost dst 0.0.0.0/32
acl manager proto cache_object
http_access allow manager localhost
acl Safe_ports port 80 # http
http_access deny !Safe_ports
acl CONNECT method CONNECT
acl SSL_ports port 443 563
http_access deny CONNECT !SSL_ports
acl PURGE method PURGE
http_access allow PURGE localhost
hierarchy_stoplist -i ^https:\\ ? cgi-bin ?
acl denyssl urlpath_regex -i ^https:\\
no_cache deny denyssl
acl QUERY urlpath_regex -i cgi-bin \? \asp \php \jsp \cgi Servlet
no_cache deny QUERY
#acl broken302 http_status 400-404 302
#http_access deny broken302
http_access allow all
#SNMP with Cacti config here
snmp_port 3401
acl snmppublic snmp_community valesquid
snmp_access allow snmppublic localhost
snmp_access deny all
#snmp_incoming_address 0000
#snmp_outgoing_address 0000
cache_peer 192.168.118.153 parent 80 0 no-query no-digest no-netdb-exchange originserver name=b #父cache,或者兄弟cache定义
cache_peer_access b allow all
refresh_pattern -i \/$ 3 90% 6 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private
refresh_pattern -i \.html$ 43200 90% 86400 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private
refresh_pattern -i \.htm$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.shtml$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.vhtml$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.hml$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.php$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.asp$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.jsp$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.gif$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.swf$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.jpg$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.png$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.bmp$ 43200 90% 129600 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.js$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.css$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.wma 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.zip 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.mp3 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.rar 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.flv$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.wmv$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.exe$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.aspx$ 43200 90% 86400 reload-into-ims ignore-reload ignore-no-cache
refresh_pattern . 43200 20% 86400
ignore-reload: 忽略http的no-cache头,reload 头
ignore-private: 忽略http的private头
ignore-no-cache:忽略Pragma: no-cache和Cache-control:no-cache头
reload-into-ims:改变no-cache为返回时间戳对比验证。
override-expire:忽略有效期验证,先考虑最小时间min.如果文件存活时间小于min,认为是新的。
override-lastmod:忽略更改时间,先考虑最小时间min.如果文件存活时间小于min,认为是新的
cache管理和查看在文档(3)中叙述
############################################################
笔者原创
作者:john
转载请注明出处