无法使用 Squid 缓存动态内容

无法使用 Squid 缓存动态内容

我正在尝试使用 squid 来缓存一些动态内容。这些内容来自诸如 之类的请求/path/{id},其中id是资源的标识符。我尝试过使用 squid 的配置文件,但到目前为止还没有成功。

它可以缓存“/path/resource”之类的内容,但对动态内容不起作用。 中access.log充满了TCP_MISS_ABORTED

这是我的配置文件:

#
# 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 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8     # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10      # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16     # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12      # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16     # RFC 1918 local private network (LAN)
acl localnet src fc00::/7           # RFC 4193 local private network range
acl localnet src fe80::/10          # RFC 4291 link-local (directly plugged) machines
acl dynamic_content urlpath_regex ^/long_text/get/[0-9]+

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

#
# 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

# This default configuration only allows localhost requests because a more
# permissive Squid installation could introduce new attack vectors into the
# network by proxying external TCP connections to unprotected services.
http_access allow localhost
http_access allow dynamic_content

# Protect web applications running on the same server as Squid. They often
# assume that only local users can access them at "localhost" ports.
http_access allow to_localhost
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
cache_mem 1000 MB
maximum_object_size 4 MB
#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp:       1440    20% 10080
refresh_pattern .       0   20% 4320

debug_options ALL,1 33,2

此外,出于测试原因,squid 服务与发出请求的客户端以及 Web 服务器在同一台服务器上运行。

编辑:对象不大于 1.5 MB

编辑2:访问日志如下所示:

1707899048.785      6 192.168.100.150 TCP_MISS/200 12592 GET http://192.168.100.150:8080/long_text/get/113 - HIER_DIRECT/192.168.100.150 text/plain
1707899048.793      7 192.168.100.150 TCP_MISS_ABORTED/200 8488 GET http://192.168.100.150:8080/long_text/get/1868 - HIER_DIRECT/192.168.100.150 text/plain
1707899048.806     11 192.168.100.150 TCP_MISS_ABORTED/200 20800 GET http://192.168.100.150:8080/long_text/get/743 - HIER_DIRECT/192.168.100.150 text/plain
1707899048.814      8 192.168.100.150 TCP_MISS_ABORTED/200 20800 GET http://192.168.100.150:8080/long_text/get/1 - HIER_DIRECT/192.168.100.150 text/plain
1707899048.821      5 192.168.100.150 TCP_MISS_ABORTED/200 8488 GET http://192.168.100.150:8080/long_text/get/1412 - HIER_DIRECT/192.168.100.150 text/plain
1707899048.828      6 192.168.100.150 TCP_MISS_ABORTED/200 12592 GET http://192.168.100.150:8080/long_text/get/566 - HIER_DIRECT/192.168.100.150 text/plain

大多数 都是TCP_MISS_ABORTED, 但 我 想说 只有 几百 个人 中 有 一个 是TCP_MISS, 但我 没有 找到TCP_MEM_HIT.

编辑:Web 服务器作为响应发送的完整标头:

Cache-Control: max-age=60
Content-Type: text/plain; charset=utf-8
Date: Wed, 14 Feb 2024 09:25:32 GMT
Transfer-Encoding: chunked

编辑:连续获取相同资源的日志:

1707902670.872     18 127.0.0.1 TCP_MISS/200 1045060 GET http://127.0.0.1:8080/long_text/get/1 - HIER_DIRECT/127.0.0.1 text/plain
1707904558.006     12 127.0.0.1 TCP_MISS/200 1045060 GET http://127.0.0.1:8080/long_text/get/1 - HIER_DIRECT/127.0.0.1 text/plain
1707904558.777     11 127.0.0.1 TCP_MISS/200 1045060 GET http://127.0.0.1:8080/long_text/get/1 - HIER_DIRECT/127.0.0.1 text/plain
1707904559.535     15 127.0.0.1 TCP_MISS/200 1045060 GET http://127.0.0.1:8080/long_text/get/1 - HIER_DIRECT/127.0.0.1 text/plain
1707904560.233     11 127.0.0.1 TCP_MISS/200 1045060 GET http://127.0.0.1:8080/long_text/get/1 - HIER_DIRECT/127.0.0.1 text/plain

答案1

您正在使用cache_mem。它不存储大于maximum_object_size_in_memory默认值 512 KB 的对象。

相关内容