如何配置 squid 来缓存所有下载的文件?

How can Squid be configured to cache all downloaded files?

我正在尝试设置一个 Squid 代理实例,以便它可以用于通过 Test Kitchen 开发 Chef 食谱。

当 Test Kitchen 启动虚拟机时,它会通过下载安装 chef-client。我已将其配置为通过代理服务器下载,但 Squid 不会缓存下载的文件,例如

认为 这可能是因为它是通过 SSL 访问的,但我不是 100% 确定。这是因为 Ubuntu VM 中的 apt 配置为使用相同的代理实例,我在这些文件的缓存中得到了命中:

这是我的 squid.conf 文件:

http_port 3128

acl manager url_regex -i ^cache_object:// +i ^https?://[^/]+/squid-internal-mgr/

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 localnet src 10.0.0.0/8     # RFC 1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC 1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC 1918 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

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 allow localnet
http_access deny all

maximum_object_size 1024 MB
cache_replacement_policy heap LFUDA
cache_dir aufs /var/spool/squid3 5000 24 256
coredump_dir /var/spool/squid3

refresh_pattern ^ftp:          1440    20%     10080
refresh_pattern ^gopher:       1440    0%      1440
refresh_pattern Packages\.bz2$ 0       20%     4320 refresh-ims
refresh_pattern Sources\.bz2$  0       20%     4320 refresh-ims
refresh_pattern Release\.gpg$  0       20%     4320 refresh-ims
refresh_pattern Release$       0       20%     4320 refresh-ims
refresh_pattern -i .(deb|rpm|exe|zip|tar|tgz|bz2|ram|rar|bin)$  129600 100% 129600 override-expire ignore-no-cache ignore-no-store
refresh_pattern .              0       20%     4320

有人知道我需要在配置中添加什么才能缓存 chef-client 的下载吗?是因为它是 SSL link 吗?

就这些情况而言,我发现它确实与 SSL 有关。

原因是 SSL 旨在提供隐私期望,因此默认情况下 Squid 不会缓存受保护的页面,因为它看不到它们。

因为我只会将其用于包缓存,所以我有两个选择:

  1. 使用纯 http url
  2. 下载 chef-client
  3. 为 Squid 创建一个自签名证书作为中间人,以便它可以解密传入的数据并缓存它。

1 号目前更容易,而从长远来看,2 号可能更稳健。