squid 安装之后无法缓存文件
近期要在web服务器上安装squid来缓存数据,但是安装完成之后,发现可以正常访问,但是查看squid日志发现没有Hit 状态的请求,都是TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT,详细如下:
请教各位
测试环境如下:
squid 80端口 ,apache 81端口 tomcat 8081端口
squid安装之后,已经可以通过80端口正常访问文件,squid 日志和 apache日志均有记录
squid日志:
119.180.98.13 - - [01/Apr/2014:19:37:03 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT
apache日志:
223.203.216.165 - - [01/Apr/2014:19:37:20 +0800] "GET /goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 -
配置文件如下:
# # Recommended minimum configuration: # # Example rule allowing access from your local networks. # Adapt to list your (internal) IP networks from where browsing # should be allowed acl localnet src 10.0.0.0/8 # RFC1918 possible internal network acl localnet src 172.16.0.0/12 # RFC1918 possible internal network acl localnet src 192.168.0.0/16 # RFC1918 possible internal network acl localnet src fc00::/7 # RFC 4193 local private network range acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines 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: # # 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 # Only allow cachemgr access from localhost http_access allow localhost manager http_access deny manager # We strongly recommend the following be uncommented to protect innocent # web applications running on the proxy server who think the only # one who can access services on "localhost" is a local user #http_access deny to_localhost # # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS # # 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 http_access allow localhost # And finally deny all other access to this proxy http_access allow all # Squid normally listens to port 3128 http_port 3128 # Uncomment and adjust the following to add a disk cache directory. #cache_dir ufs /usr/local/squid/var/cache/squid 100 16 256 # Leave coredumps in the first cache dir coredump_dir /usr/local/squid/var/cache/squid # # 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 .htm$ 10 20% 1440 #refresh_pattern -i .jsp$ 10 20% 1440 #add by maple visible_hostname cloud.icm.cn http_port 223.203.216.165:80 vhost vport #xx.xx.xx.xx为这台服务器的IP地址 icp_port 0 cache_mem 400 MB #设置Squid所能使用的内存共400MB,这个值因人而异 cache_swap_low 90 cache_swap_high 95 maximum_object_size 20000 KB #最大缓存文件大小,超过这个值则不缓存,这个值因人而异 maximum_object_size_in_memory 4096 KB #装入内存缓存的文件大小,这个值对Squid的性能影响比较大,因为默认值是8K,超过8K的文件都不装入内存,而实际应用中很多网页和图片等都超过8KB, 个人认为如果缓存不装入内存而存在磁盘上,性能和apache直接读取磁盘文件没什么区别,甚至不如直接访问apache,现在设置成小于4兆的文件通通>装入内存缓存. cache_dir ufs /tmp1 10000 16 256 #磁盘缓存的类型和目录,大小,一二级目录的设置,这里磁盘缓存大小是10G cache_store_log none #这个设置是不记录store.log emulate_httpd_log off #打开emulate_httpd_log选项,将使Squid仿照Aapche的日志格式 logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh #日志格式combined的设置 pid_filename /var/log/squid/squid.pid cache_log /var/log/squid/cache.log access_log /var/log/squid/access.log combined #这里是设置pid和日志文件的位置,因人而异,同时日志格式是combined,awstats可以直接调用分析了 acl all src 0.0.0.0/0.0.0.0 acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe cache deny QUERY #设置不想缓存的目录或者文件类型 acl picurl url_regex -i .bmp$ .png$ .jpg$ .gif$ .jpeg$ acl mystie1 referer_regex -i aaa http_access allow mystie1 picurl acl mystie2 referer_regex -i bbb http_access allow mystie2 picurl #设置防图片盗链的,其中aaa,和bbb分别是虚拟主机的域名,referer中必须包含有aaa或者bbb的域名才能访问图片 acl nullref referer_regex -i ^$ http_access allow nullref acl hasref referer_regex -i .+ http_access deny hasref picurl #设置允许直接访问图片和拒绝referer中没有包含aaa或着bbb的访问图片 cache_peer 223.203.216.165 parent 81 0 no-query originserver login=PASS #xx.xx.xx.xx还是本机服务器的IP,81则是apache的端口,如果你的虚拟主机有用户名和密码保护起来的目录必须设置login=PASS,否则认证会失效 cache_effective_user nobody cache_effective_group nobody #squid使用的用户组和用户名
附录squid完整日志:
119.180.98.13 - - [01/Apr/2014:19:37:03 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT 119.180.98.13 - - [01/Apr/2014:19:37:04 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT 119.180.98.13 - - [01/Apr/2014:19:37:05 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT 119.180.98.13 - - [01/Apr/2014:19:37:05 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT 119.180.98.13 - - [01/Apr/2014:19:37:19 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT 119.180.98.13 - - [01/Apr/2014:19:37:19 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT 119.180.98.13 - - [01/Apr/2014:19:37:19 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT 119.180.98.13 - - [01/Apr/2014:19:37:20 +0800] "GET http://cloud.icm.cn/goldenkey/uploadfiles/image/2014/01/20140121115623_902.jpg HTTP/1.1" 304 257 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" TCP_REFRESH_UNMODIFIED:FIRSTUP_PARENT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
efresh_pattern -i .htm$ 10 20% 1440 我加了这个之后也不行