鱿鱼不缓存

Abh*_*nda 8 cache squid apache-2.2

我正在尝试将 Squid 配置为缓存服务器。我有一个局域网,其中网络服务器 (apache) 位于192.168.122.11squid 处,192.168.122.21而我的客户端位于192.168.122.22. 问题是,当我查看 Squid 的访问日志时,我看到的只是TCP_MISS消息。Squid 似乎根本没有缓存。我检查了缓存目录是否具有所有适当的权限。这里还有什么问题?这是我的鱿鱼配置:

acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.1/8 0.0.0.0/32 ::1
acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591
acl Safe_ports port 777
acl CONNECT method CONNECT
http_access allow all
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 accel defaultsite=cona-proxy vhost
cache_peer 192.168.122.11 parent 80 0 no-query originserver login=PAS name=webserver
cache_dir ufs /var/spool/squid3 100 16 256
coredump_dir /var/spool/squid3
refresh_pattern ^ftp:   1440    20% 10080
refresh_pattern ^gopher:    1440    0%  1440
refresh_pattern -i (/cgi-bin/|\?)   0   0%  0
refresh_pattern (Release|Packages(.gz)*)$   0   20% 2880
refresh_pattern .   0   20% 4320
always_direct allow all
acl server_users dstdomain cona-proxy
http_access allow server_users
cache_peer_access webserver allow server_users
cache_peer_access webserver deny all
Run Code Online (Sandbox Code Playgroud)

在所有机器中,cona-proxy指向192.168.122.21(在 中添加/etc/hosts

输出 curl -v 192.168.122.11

* About to connect() to 192.168.122.11 (#0)
* Trying 192.168.122.11... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libculr/7.22.0 OpneSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: 192.168.122.11
> Accept: */*
>
< HTTP/1.1 202 OK
< Date Mon, 02 Jul 2012 05:48:50 GMT
< Server: Apache/2.2.22 (Ubuntu)
< Last-Modified: Tue, 19 Jun 2012 23:04:25 GMT
< ETag: "27389-b1-4c2db4dc2c182"
< Accept_Ranges: bytes
< Content-Length: 177
< Vary: Accept-Encoding
< Content-Type: text/html
< X-Pad: avoid browser bug
<
<html><body><h1>It works!</h1>
<p>This is the default web page for the server.</p>
<p>The web server software is running but no content has been added, yet. </p>
</body></html>
* Connection #0 to host 192.168.122.11 left intact
* Closing connection #0
Run Code Online (Sandbox Code Playgroud)

小智 9

根据我的经验,Squid 拒绝缓存内容的 3 个最常见原因是:

  • 缓存目录权限,您已经解决了这个问题。好的 :)
  • http_access,但这不是您的情况,因为您TCP_MISS在 access.log中看到了行
  • refresh_pattern 指令

refresh_pattern 指令控制 Squid 如何认为对象是新鲜的还是陈旧的,特别是与浏览器发出请求的方式以及交换哪些缓存控制 HTTP 标头有关。

refresh_pattern你在你的配置有线条squid的默认行。但是,我 2 周前才在 Ubuntu 上安装了 Squid,使用这些默认设置,它几乎不缓存任何内容。

Squid 关于 refresh_pattern 的文档应该解释每一行的含义,但我实际上无法理解该文档的含义。显然我并不孤单:)

我建议您添加以下一种或多种模式并测试特定文件/URL,直到您满意为止。例子:

refresh_pattern -i \.(gif|png|jpg|jpeg|ico)$ 3600 90% 43200
Run Code Online (Sandbox Code Playgroud)

有了这个,你告诉 Squid 考虑所有图标/图片可缓存至少 1 小时到最多半天。您的浏览器可能会发送带有特定缓存标头的 HTTP 请求,这会导致 Squid 以任何方式回复TCP_MISS。要强制缓存回复,甚至打破客户的期望,您可以这样做:

refresh_pattern -i \.(gif|png|jpg|jpeg|ico)$ 3600 90% 43200 override-expire ignore-no-cache ignore-no-store ignore-private
Run Code Online (Sandbox Code Playgroud)

更大的电影/音频/iso文件也是如此:

refresh_pattern -i \.(mp[34g]|swf|wav|...)$ 43200 90% 432000
Run Code Online (Sandbox Code Playgroud)

如果其他任何事情都失败了,请使用强大的锤子 :) 但我建议这样做:

refresh_pattern . 3600    80%     14400
Run Code Online (Sandbox Code Playgroud)

用它告诉 Squid 它可以缓存所有内容至少 1 小时。但是,这几乎肯定会破坏动态应用程序。如果您尝试缓存的服务器主要由静态内容组成,请使用它。

另外,不要忘记maximum_object_size. 默认情况下,它是20Mb。如果您尝试缓存的对象大于该值,Squid 将不会缓存它们。我将它提高了 10 倍,达到 200Mb。天啊。

maximum_object_size 204800 KB
Run Code Online (Sandbox Code Playgroud)

顺便说一句,您的cache_peer行不正确,因为它指向 Apache。一个cache_peer鱿鱼讲是在高速缓存架构中的另一个squid实例上涨,通常用于在过去的ISP的缓存服务器。只需删除该行。

还有祝你好运 :)


Jan*_*rek 3

在你的配置中你错过了这一行:

acl myhosts src 192.168.0.0/255.255.0.0 (your internal network/netmask)
http_access allow myhosts
Run Code Online (Sandbox Code Playgroud)

编辑1:

您的网络服务器不是您的cache_peer。请从您的配置文件中删除此行。Squid 有另一种类型的协议(ICP)来实现缓存之间的互操作性,而 apache 不知道这种协议。