前言:基于宽带稳定性、带宽等问题,搭建WEB CACHE缓存服务器。
目的:从大概率上屏蔽从远程web服务器抓取数据,频繁访问的数据,将数据缓存在本地服务器,从而降低对对外网的请求。SourceByrd's Weblog-https://note.t4x.org/project/lan-squid-cache-server-configuration/
配置:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# # Recommended minimum configuration: # acl manager proto cache_object acl localhost src 127.0.0.1/32 ::1 #本地主机、源地址 acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1 #目标主机 # Example rule allowing access from your local networks. # Adapt to list your (internal) IP networks from where browsing # should be allowed acl localnet src 192.168.1.0/24 # RFC1918 possible internal network #运行访问此代理的本地网络 acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT # # Recommended minimum Access Permission configuration: # # Only allow cachemgr access from localhost http_access allow manager localhost http_access deny manager # Deny requests to certain unsafe ports http_access deny !Safe_ports #拒绝安全端口以外的端口 # Deny CONNECT to other than secure SSL ports http_access deny CONNECT !SSL_ports #拒绝443端口以外的端口 # Example rule allowing access from your local networks. # Adapt localnet in the ACL section to list your (internal) IP networks # from where browsing should be allowed http_access allow localnet #允许localnet http_access allow localhost http_access allow all #允许所有 # Squid normally listens to port 3128 http_port 192.168.1.254:3128 intercept #设置透明代理 http_port 3130 #非透明代理 # We recommend you to use at least the following line. # Uncomment and adjust the following to add a disk cache directory. cache_dir aufs /var/spool/squid 20480 16 256 #硬盘缓存大小 # Leave coredumps in the first cache dir coredump_dir /var/spool/squid #存储位置 ######################################################## visible_hostname squid.t4x.org #主机名 cache_mgr root@t4x.org #管理员 dns_nameservers 192.168.1.254 #dns地址 cache_mem 700 MB #建议为内存的25%-50%之间,太大可能导致死机 half_closed_clients off #一旦从客户端 返回“no more data to read”的信息,squid就立即关闭该连接 cache_swap_high 90% #当缓存空间达到设定的数值后,新内容将取代旧的内容,而不直接添加到缓存中 cache_swap_low 80% #当缓存内容低于在此设定的数值时,文件直接添加到缓存中,而不是取代缓存中的旧文件。 maximum_object_size 1024 KB #设置缓存服务器中缓存文件的大小,在设定数值范围外的文件将不被缓存。 # Define Cache hierarchy_stoplist cgi-bin ? \.php$ \.html$ \.htm$ \.asp$ \.aspx$ \.jsp$ #RUL地址中包括cgi-bin的不进行缓存 acl taobao url_regex -i \.taobao\.com$ \.taobaocdn\.com$ \.alicdn\.com$ #URL规则表达式匹配 acl etao url_regex -i \.etao\.com$ # acl cache urlpath_regex -i \.jpg$ \.gif$ \.png$ \.bmp$ \.jpeg$ \.css$ \.js$ \.xml$ #对以上类型的进行缓存 acl nocache urlpath_regex -i \.psd$ \.mp3$ \.mp4$ \.wmv$ \.wav$ \.flv$ \.dat$ #略去协议和主机名的URL规则表达式匹配 #acl sina dstdomain .sina.com.cn .sina.com #拒绝访问sina.com和sina.com.cn #http_access deny sina #拒绝sina no_cache deny etao no_cache deny nocache no_cache allow taobao no_cache allow cache ######################################################## # Add any of your own refresh_pattern entries above these. refresh_pattern ^ftp: 1440 20% 10080 #仅应用到没有明确过时期限的响应 refresh_pattern ^gopher: 1440 0% 1440 #过期校验 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern . 0 20% 4320 refresh_pattern -i \.css$ 360 50% 2880 reload-into-ims #当有no-cache的请求发过来时,他会发一个http头部回去问源服务器(上层服务器),是否有修改,如果修改就更新,如果没有就返回给客户. #refresh_pattern -i \.css$ 360 50% 1440 ignore-reload #强制缓存 refresh_pattern -i \.js$ 1440 50% 2880 reload-into-ims #refresh_pattern -i \.js$ 1440 50% 2880 ignore-reload refresh_pattern -i \.taobao$ 1440 50% 2880 ignore-reload refresh_pattern -i \.alicdn$ 1440 50% 2880 ignore-reload refresh_pattern -i \.taobaocdn$ 1440 50% 2880 ignore-reload refresh_pattern -i \.jpg$ 1440 50% 2880 ignore-reload refresh_pattern -i \.gif$ 1440 50% 2880 ignore-reload refresh_pattern -i \.jpg$ 1440 50% 2880 ignore-reload #缓存24小时,最大保留48小时 refresh_pattern -i \.png$ 1440 50% 2880 ignore-reload refresh_pattern -i \.bmp$ 1440 50% 2880 ignore-reload refresh_pattern -i \.doc$ 1440 50% 2880 ignore-reload refresh_pattern -i \.ppt$ 1440 50% 2880 ignore-reload refresh_pattern -i \.xls$ 1440 50% 2880 ignore-reload refresh_pattern -i \.pdf$ 1440 50% 2880 ignore-reload refresh_pattern -i \.txt$ 1440 50% 2880 ignore-reload |
效果测试:chrome浏览器chrome://net-internals/#events
参考:http://note.t4x.org/system/config-suqid-transparent-proxy/
参考:http://note.t4x.org/system/squid-cache-config/
申明:本文由BYRD原创(基于squid-3.1.10),未经许可禁止转载!SourceByrd's Weblog-https://note.t4x.org/project/lan-squid-cache-server-configuration/ SourceByrd's Weblog-https://note.t4x.org/project/lan-squid-cache-server-configuration/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!