Squid 不会存储我的图片

Squid 不会存储我的图片

在花费数小时配置 squid 3.2.5 后,我只得到了 TCP_MISS。为了缩小问题范围,我将重点放在一个我想要缓存的 PNG 文件上,但请注意,我为每个请求都得到了 TCP_MISS,而不仅仅是 PNG 文件。PNG 文件可以在这个地址。刷新也没用。

当我尝试通过 squid 加载它时,我在 access.log 中收到以下行:

1357671721.566 127 127.0.0.1 TCP_MISS/200 618 获取http://flags.tatoeba.org/img/flags/epo.png- HIER_DIRECT/86.65.39.22 图片/png

cache.log 中的内容如下:

2013/01/08 20:02:59.768 kid1| client_side.cc(2298) parseHttpRequest: HTTP Client local=127.0.0.1:3303 remote=127.0.0.1:42816 FD 19 flags=1
2013/01/08 20:02:59.769 kid1| client_side.cc(2299) parseHttpRequest: HTTP Client REQUEST:
---------
GET http://flags.tatoeba.org/img/flags/epo.png HTTP/1.1
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: flags.tatoeba.org
Connection: Close
Proxy-Connection: Keep-Alive


----------
2013/01/08 20:02:59.856 kid1| http.cc(2221) httpStart: httpStart: "GET http://flags.tatoeba.org/img/flags/epo.png"
2013/01/08 20:02:59.856 kid1| http.cc(2177) sendRequest: HTTP Server local=192.168.1.13:56866 remote=86.65.39.22:80 FD 22 flags=1
2013/01/08 20:02:59.856 kid1| http.cc(2178) sendRequest: HTTP Server REQUEST:
---------
GET /img/flags/epo.png HTTP/1.1
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: flags.tatoeba.org
Via: 1.1 nomada (squid/3.2.5)
Cache-Control: max-age=15600540
Connection: keep-alive


----------
2013/01/08 20:02:59.898 kid1| ctx: enter level  0: 'http://flags.tatoeba.org/img/flags/epo.png'
2013/01/08 20:02:59.898 kid1| http.cc(689) processReplyHeader: processReplyHeader: key 'EA06B401749A4C13ED95E8B5788A3010'
2013/01/08 20:02:59.898 kid1| http.cc(732) processReplyHeader: HTTP Server local=192.168.1.13:56866 remote=86.65.39.22:80 FD 22 flags=1
2013/01/08 20:02:59.898 kid1| http.cc(733) processReplyHeader: HTTP Server REPLY:
---------
HTTP/1.1 200 OK
Date: Tue, 08 Jan 2013 19:03:18 GMT
Server: Apache/2.2.16 (Debian)
Accept-Ranges: bytes
Content-Length: 219
Vary: User-Agent
Expires: Fri, 21 Dec 2012 00:00:00 GMT
Cache-Control: public, no-transform
Content-Type: image/png
Via: 1.1 tatoeba.fsffrance.org
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive

�PNG


----------
2013/01/08 20:02:59.898 kid1| ctx: exit level  0
2013/01/08 20:02:59.898 kid1| ctx: enter level  0: 'http://flags.tatoeba.org/img/flags/epo.png'
2013/01/08 20:02:59.898 kid1| http.cc(910) haveParsedReplyHeaders: haveParsedReplyHeaders: HTTP CODE: 200
2013/01/08 20:02:59.898 kid1| http.cc(640) httpMakeVaryMark: httpMakeVaryMark: user-agent="Wget%2F1.14%20(linux-gnu)"
2013/01/08 20:02:59.898 kid1| ctx: exit level  0
2013/01/08 20:02:59.899 kid1| client_side.cc(1362) sendStartOfMessage: HTTP Client local=127.0.0.1:3303 remote=127.0.0.1:42816 FD 19 flags=1
2013/01/08 20:02:59.899 kid1| client_side.cc(1363) sendStartOfMessage: HTTP Client REPLY:
---------
HTTP/1.1 200 OK
Date: Tue, 08 Jan 2013 19:03:18 GMT
Server: Apache/2.2.16 (Debian)
Accept-Ranges: bytes
Content-Length: 219
Vary: User-Agent
Expires: Fri, 21 Dec 2012 00:00:00 GMT
Cache-Control: public, no-transform
Content-Type: image/png
X-Cache: MISS from nomada
X-Cache-Lookup: MISS from nomada:3303
Via: 1.1 tatoeba.fsffrance.org, 1.1 nomada (squid/3.2.5)
Connection: keep-alive


----------
2013/01/08 20:02:59.899 kid1| http.cc(1044) persistentConnStatus: local=192.168.1.13:56866 remote=86.65.39.22:80 FD 22 flags=1 eof=0

我的配置文件看起来很像默认文件,除了几个变化:

cache_effective_user squid
cache_effective_group squid
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 Safe_ports port 901     # SWAT
acl CONNECT method CONNECT
http_access allow localhost manager
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
debug_options ALL,1 11,3 31,3 65,3
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3303
cache_dir ufs /var/cache/squid 600 16 256
cache_mem 256 MB
coredump_dir /var/cache/squid
refresh_pattern ^ftp:       1440    20% 10080
refresh_pattern -i \.(gif|png|jpg|jpeg|ico|bmp)$ 260000 90% 260009 override-expire ignore-no-cache ignore-no-store ignore-private
refresh_pattern ^gopher:    1440    0%  1440
refresh_pattern -i (/cgi-bin/|\?) 0 0%  0
refresh_pattern .       0   20% 4320

我的缓存目录属于 squid:squid,所以那边也没有问题。我被难住了,不知道该怎么回答。

这是我的 access.log 的一部分:

1357671487.203    212 127.0.0.1 TCP_MISS/200 8263 GET http://i2.ytimg.com/vi/mwKa-gjx14k/mqdefault.jpg - HIER_DIRECT/74.125.230.238 image/jpeg
1357671487.235    134 127.0.0.1 TCP_MISS/200 10762 GET http://i4.ytimg.com/vi/O0bftzEOt9c/mqdefault.jpg - HIER_DIRECT/74.125.230.224 image/jpeg
1357671487.296    253 127.0.0.1 TCP_MISS/200 7415 GET http://i4.ytimg.com/vi/GPUnq0JSqRk/mqdefault.jpg - HIER_DIRECT/74.125.230.224 image/jpeg
1357671488.188    474 127.0.0.1 TCP_MISS/200 294 POST http://serverfault.com/posts/0/editor-heartbeat/ask - HIER_DIRECT/69.59.197.21 application/json
1357671505.309    255 127.0.0.1 TCP_MISS/204 533 GET http://s.youtube.com/s? - HIER_DIRECT/74.125.230.224 text/html
1357671516.404      0 127.0.0.1 TCP_MISS/503 6350 GET http://s.youtube.com/s? - HIER_NONE/- text/html
1357671533.221      0 127.0.0.1 TCP_MISS/503 4106 POST http://serverfault.com/posts/0/editor-heartbeat/ask - HIER_NONE/- text/html
1357671582.022    481 127.0.0.1 TCP_MISS/200 439 POST http://serverfault.com/posts/0/editor-heartbeat/ask - HIER_DIRECT/69.59.197.21 application/json
1357671597.029   1543 127.0.0.1 TCP_MISS/200 9700 GET http://tatoeba.org/eng/sentences/show/673940 - HIER_DIRECT/86.65.39.22 text/html
1357671597.166     47 127.0.0.1 TCP_MISS/200 1426 GET http://tatoeba.org/js/sentences.random.js? - HIER_DIRECT/86.65.39.22 application/javascript
1357671597.205     86 127.0.0.1 TCP_MISS/200 2174 GET http://tatoeba.org/js/sentences_lists.menu.js? - HIER_DIRECT/86.65.39.22 application/javascript
1357671597.254    136 127.0.0.1 TCP_MISS/200 1522 GET http://css.tatoeba.org/css/sentences/show.css? - HIER_DIRECT/86.65.39.22 text/css
1357671597.254    136 127.0.0.1 TCP_MISS/200 1324 GET http://css.tatoeba.org/css/elements/furigana.css - HIER_DIRECT/86.65.39.22 text/css
1357671597.254     48 127.0.0.1 TCP_MISS/200 1809 GET http://tatoeba.org/favicon.ico - HIER_DIRECT/86.65.39.22 image/x-icon
1357671597.258    137 127.0.0.1 TCP_MISS/200 1150 GET http://js.tatoeba.org/js/furigana.js - HIER_DIRECT/86.65.39.22 application/javascript
1357671597.258    139 127.0.0.1 TCP_MISS/200 1339 GET http://js.tatoeba.org/js/generic_functions.js? - HIER_DIRECT/86.65.39.22 application/javascript
1357671597.258     91 127.0.0.1 TCP_MISS/200 2471 GET http://js.tatoeba.org/js/autocompletion.js - HIER_DIRECT/86.65.39.22 application/javascript
1357671597.295    179 127.0.0.1 TCP_MISS/200 3232 GET http://css.tatoeba.org/css/layouts/default.css - HIER_DIRECT/86.65.39.22 text/css
1357671597.332     39 127.0.0.1 TCP_MISS/200 1234 GET http://css.tatoeba.org/css/elements/navigation.css - HIER_DIRECT/86.65.39.22 text/css
1357671597.339     43 127.0.0.1 TCP_MISS/200 1809 GET http://tatoeba.org/favicon.ico - HIER_DIRECT/86.65.39.22 image/x-icon
1357671597.342     49 127.0.0.1 TCP_MISS/200 1774 GET http://css.tatoeba.org/css/elements/sentences_group.css - HIER_DIRECT/86.65.39.22 text/css
1357671597.377     82 127.0.0.1 TCP_MISS/200 1032 GET http://css.tatoeba.org/css/elements/logs_colors.css - HIER_DIRECT/86.65.39.22 text/css
1357671597.384     90 127.0.0.1 TCP_MISS/200 1014 GET http://css.tatoeba.org/css/elements/comment.css - HIER_DIRECT/86.65.39.22 text/css
1357671597.384     89 127.0.0.1 TCP_MISS/200 1124 GET http://css.tatoeba.org/css/elements/autocompletion.css - HIER_DIRECT/86.65.39.22 text/css
1357671597.384     89 127.0.0.1 TCP_MISS/200 1023 GET http://css.tatoeba.org/css/elements/logs_annexe.css - HIER_DIRECT/86.65.39.22 text/css
1357671597.410    292 127.0.0.1 TCP_MISS/200 21703 GET http://js.tatoeba.org/js/jquery-mini.js - HIER_DIRECT/86.65.39.22 application/javascript
1357671597.794    131 127.0.0.1 TCP_MISS/200 1284 GET http://flags.tatoeba.org/img/valid_16x16.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.795    133 127.0.0.1 TCP_MISS/200 595 GET http://flags.tatoeba.org/img/arrow_down.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.800    137 127.0.0.1 TCP_MISS/200 1256 GET http://flags.tatoeba.org/img/add_to_list.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.801    137 127.0.0.1 TCP_MISS/200 618 GET http://flags.tatoeba.org/img/flags/epo.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.846     50 127.0.0.1 TCP_MISS/200 1180 GET http://flags.tatoeba.org/img/direct_translation.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.846     51 127.0.0.1 TCP_MISS/200 3008 GET http://flags.tatoeba.org/img/loading.gif - HIER_DIRECT/86.65.39.22 image/gif
1357671597.846     45 127.0.0.1 TCP_MISS/200 1539 GET http://flags.tatoeba.org/img/flags/eng.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.847     45 127.0.0.1 TCP_MISS/200 532 GET http://flags.tatoeba.org/img/flags/nld.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.860    197 127.0.0.1 TCP_MISS/200 1072 GET http://flags.tatoeba.org/img/loading-small.gif - HIER_DIRECT/86.65.39.22 image/gif
1357671597.887    224 127.0.0.1 TCP_MISS/200 16497 GET http://flags.tatoeba.org/img/TatoebaProjectBeta.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.892     45 127.0.0.1 TCP_MISS/200 1031 GET http://flags.tatoeba.org/img/indirect_translation.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.892     45 127.0.0.1 TCP_MISS/200 520 GET http://flags.tatoeba.org/img/flags/ita.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.892     45 127.0.0.1 TCP_MISS/200 525 GET http://flags.tatoeba.org/img/flags/deu.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.892     44 127.0.0.1 TCP_MISS/200 718 GET http://flags.tatoeba.org/img/flags/jpn.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.908     47 127.0.0.1 TCP_MISS/200 541 GET http://css.tatoeba.org/img/bg_main.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.930     43 127.0.0.1 TCP_MISS/200 694 GET http://css.tatoeba.org/img/search_bar_body.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.933     39 127.0.0.1 TCP_MISS/200 584 GET http://css.tatoeba.org/img/module_background.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.935     42 127.0.0.1 TCP_MISS/200 1572 GET http://css.tatoeba.org/img/search_bar_right.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.936     43 127.0.0.1 TCP_MISS/200 1574 GET http://css.tatoeba.org/img/search_bar_left.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.936     42 127.0.0.1 TCP_MISS/200 1378 GET http://css.tatoeba.org/img/title.png - HIER_DIRECT/86.65.39.22 image/png
1357671597.954     45 127.0.0.1 TCP_MISS/200 1026 GET http://css.tatoeba.org/img/audio_unavailable.png - HIER_DIRECT/86.65.39.22 image/png

答案1

上游网络服务器返回的是过去的到期时间,这将导致 Squid 立即认为该对象已过时。

Expires: Fri, 21 Dec 2012 00:00:00 GMT

这看起来像一个硬编码的时间戳,您可能希望网络服务器返回一个相对的到期时间戳(例如现在加上 1 个月)。

答案2

如果您发现此答案是因为 Squid 没有缓存您期望的对象,请尝试debug_options = ALL,2设置/etc/squid3/squid.conf

记录响应标头后,请留意如下行:

store.cc(1003) checkCachable: StoreEntry::checkCachable: NO: too big

这可能是由于maximum_object_size设置得太低(默认值为 4 MB)或此处描述了鱿鱼虫(还归档于 Ubuntu 启动板),如果它出现在之后,就会被maximum_object_size忽略,就像在标准分布式配置文件模板中那样。cache_dirsquid.conf

store.cc(994) checkCachable: StoreEntry::checkCachable: NO: not cachable

非缓存也可能是由于远程服务器试图禁用客户端或代理缓存而导致的,方法是随回复一起发送各种标头(如HTTP 标准), 例如:

  • Expires使用过去的日期(强制立即到期),或
  • Cache-control: no-cache或者Cache-control: private

客户端(例如 Web 浏览器)也可以明确禁用缓存。例如,如果您使用 Reload 或 force-reload 选项,这取决于浏览器,但通常:

  • 按 F5 或 Shift-F5 键,或者
  • 无论是否按下 Shift 键,都单击“重新加载”按钮。

然后浏览器将明确禁用缓存,可能使用以下机制之一(另请参阅RFC 2616 第 14.9.4 节):

有时,用户代理可能希望或需要坚持要求缓存通过源服务器重新验证其缓存条目(而不仅仅是通过到源服务器路径上的下一个缓存),或从源服务器重新加载其缓存条目。如果缓存或源服务器高估了缓存响应的过期时间,则可能需要端到端重新验证。如果缓存条目由于某种原因损坏,则可能需要端到端重新加载。

客户端可以使用 Cache-Control 请求指令指定这三种操作:...

该请求包含“no-cache”缓存控制指令,或者为了与 HTTP/1.0 客户端兼容,“Pragma: no-cache”。

如果您想确保客户端没有故意禁用缓存,您可以wget使用 Squid/HTTP 代理下载相同的文件来测试它:

http_proxy=http://yourproxy:3128 wget -O /dev/null http://yourhost/yourfile

并检查 Squid 日志以查看请求发生了什么,以及 Squid 是否决定缓存响应,以及原因(参见上文)。

相关内容