- cache_effective_user squid #运行squid的用户
- cache_effective_group squid #运行squid的用户所在的组
- visible_hostname squid1.cache.cn #设定squid的主机名,如无此项squid将无法启动
- http_port 80 accel vhost vport #代理端口
- icp_port 3130 #icp端口
- # 配置其他缓存服务器,当squid1在其缓存中没有找到请求的资源时,通过ICP查询去其邻居中取得缓存
- cache_peer 192.168.0.150 sibling 80 3130
- # 后端web服务器配置,round-robin表示通过轮询方式将请求分发到其中一台web节点
- cache_peer 192.168.0.108 parent 80 0 no-query originserver round-robin name=webServer1
- cache_peer 192.168.0.109 parent 80 0 no-query originserver round-robin name=webServer2
- cache_peer 192.168.1.115 parent 80 0 no-query originserver round-robin name=webServer3
- cache_peer_domain webServer1 webServer2 webServer3 .xuad.com #根据通配域名xuad.com来进行转发
- # 下面三行是配置访问控制的
- acl localnet src 192.168.0.149 192.168.0.150 #配置同级代理服务器IP段
- http_access allow all #允许以上所有规则通过
- icp_access allow localnet #允许localnet规则通过
- # URL中包含cgi-bin和以https:\\开头的都不缓存,asp、cgi、php、jsp等动态页面也不缓存
- hierarchy_stoplist cgi-bin ?
- hierarchy_stoplist -i ^https:\\ ?
- acl QueryString urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi
- acl denyssl urlpath_regex -i ^https:\\
- no_cache deny QueryString
- no_cache deny denyssl
- # 日志和缓存目录的设置
- cache_log /usr/local/squid/var/logs/cache.log #cache.log日志文件存放目录
- access_log /usr/local/squid/var/logs/access.log squid #access.log日志文件存放目录
- cache_dir aufs /var/cache 1024 16 256 #设定缓存目录cache,目录容量最大1024M,16*256级子目录
- cache_dir aufs /var/squid 3072 16 256 #设定缓存目录squid,目录容量最大3072M,16*256级子目录
- cache_mem 128 MB #squid用于缓存的内存容量
- # 当缓存目录空间使用达到95%以上时,新的内容将取代旧的内容,直到空间又下降到90%才停止这一活动
- cache_swap_low 90
- cache_swap_high 95
- # 设置存储策略
- maximum_object_size 4096 KB #能缓存的最大对象为4M
- maximum_object_size_in_memory 80 KB #内存中缓存的最大对象80K
- ipcache_size 1024 #缓存DNS解析得到的IP,最大单个对象为1024K
- ipcache_low 90
- ipcache_high 95
- cache_replacement_policy lru #缓存替换策略
- memory_replacement_policy lru #内存替换策略
- memory_pools on #开启内存池
- memory_pools_limit 32 MB #限制内存池大小为32MB
- forwarded_for on #开启转发
- log_icp_queries off #关闭icp查询日志
- forward_timeout 20 seconds #允许转发超时20秒
- connect_timeout 30 seconds #连接到其他机器的最大尝试时间
- read_timeout 3 minutes #允许读取超时3分钟
- request_timeout 1 minutes #允许返回超时1分钟
- persistent_request_timeout 30 seconds #允许持续连接超时30秒
- client_lifetime 15 minutes #客户端会话保持
- shutdown_lifetime 5 seconds
- negative_ttl 30 seconds #设置错误信息的生存时间
- # 允许一个IP最大并发数为50
- acl OverConnLimit maxconn 50
- http_access deny OverConnLimit
- client_persistent_connections off #对客户端长连接KeepAlive这个参数的支持
- server_persistent_connections on # 开启服务端的KeepAlive,web端要开启KeepAlive,不然这里打开是没用的
- tcp_recv_bufsize 65535 bytes #TCP套接字接收缓冲区大小
- half_closed_clients off #当客户与squid的连接处于半关闭状态时,允许squid立即关闭连接
- via on #开启转发循环的检测
- request_header_access via deny all #避免由于两台squid的主机名一样而返回403错误
- httpd_suppress_version_string off #错误页面不显示squid的版本信息
- ie_refresh off #是否允许对旧版本的IE浏览器强制刷新页面
注:shutdown_lifetime 5 seconds说明:当收到SIGTERM 或者 SIGHUP 信号后,squid将进入一种shutdown pending的模式,等待所有活动的套接字关闭。在过了shutdown_lifetime所定义的时间后,所有活动的用户都将收到一个超时信息。缺省值为30秒。