通过查看Squid3 ,我发现Squid它不caching静态资源,例如:
1379041607.923 611 127.0.0.1 TCP_MISS/304 356 GET http://www.deckle.co.uk/squid-users-guide/css/site.css - DIRECT/95.172.21.186 -
这个css的请求返回一个TCP_MISS (甚至在重新加载之后),并且图像,javascripts,htmls等等也发生了同样的情况。实际上,几乎所有的请求都得到了TCP_MISS ,只有less数例外。
如果我们看一下这个头像,我们看到它应该caching它:
$ http http://www.deckle.co.uk/squid-users-guide/css/site.css HTTP/1.1 200 OK Accept-Ranges: bytes Cache-Control: max-age=604800 Content-Encoding: gzip Content-Length: 482 Content-Type: text/css Date: Fri, 13 Sep 2013 03:07:09 GMT ETag: "d6007-30e-4d2a2f615c780" Expires: Fri, 20 Sep 2013 03:07:09 GMT Last-Modified: Sun, 06 Jan 2013 18:34:22 GMT Server: Apache/2.2.22 (Ubuntu) Vary: Accept-Encoding
我的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 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 http_access allow manager localhost http_access deny manager http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow localhost http_access deny all http_port 3128 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 http_access allow localhost http_access allow all cache_dir ufs /var/cache/squid3 10000 16 256
我错过了什么? 为什么我得到这么多TCP_MISS和鱿鱼甚至没有caching静态资源?
远程Web服务器返回HTTP 304(未修改)。 这意味着浏览器已经有一个caching的副本,服务器指示浏览器使用它,并没有发送一个新的副本。 因此,squid没有什么可以caching的。
我得到了与Squid 3.3.8相同的行为(在编写本文时,在Ubuntu 14.10上最新的包)
在这里挖掘之后,我发现当Vary Header出现时,CSS和JS的cachingerror handling实际上是一个bug,在后续版本中被修复。
从源码安装squid 3.4.10,使这个问题变得不那么明显了。