gpt4 book ai didi

apache - Varnish :可缓存但未缓存

转载 作者:行者123 更新时间:2023-12-03 17:45:43 24 4
gpt4 key购买 nike

如果我运行此命令

varnishtop -i txurl

该请求是“可缓存的”,但不是“已缓存的”。我看到“年龄= 0”(保留在 Varnish 中的年龄),如何进行编辑?

这是我的.php页面的请求

GET-使用的http://example.com
User-Agent: lwp-request/5.810

200 OK
Cache-Control: max-age=60, public, must-revalidate
Connection: close
Date: Sat, 18 Feb 2012 12:14:33 GMT
Via: 1.1 varnish
Age: 0
Server: Apache
Vary: Accept-Encoding
Content-Type: text/html
Expires: Sat, 18 Feb 2012 12:24:33 GMT
Client-Date: Sat, 18 Feb 2012 12:14:34 GMT
Client-Peer: 173.236.219.104:80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
X-Cache: MISS
X-Cacheable: YES
X-Varnish: 840966561

.htaccess代码
# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers

# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "public, must-revalidate"
</filesMatch>
</ifModule>

Default.vlc
backend default {
.host = "173.236.219.104";
.port = "81";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}

sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}

sub vcl_fetch {

# Varnish determined the object was not cacheable
if (beresp.ttl <= 0s) {
set beresp.http.X-Cacheable = "NO:Not Cacheable";

# You don't wish to cache content for logged in users
} elsif (req.http.Cookie ~ "(UserID|_session)") {
set beresp.http.X-Cacheable = "NO:Got Session";
return(hit_for_pass);

# You are respecting the Cache-Control=private header from the backend
} elsif (beresp.http.Cache-Control ~ "private") {
set beresp.http.X-Cacheable = "NO:Cache-Control=private";
return(hit_for_pass);

# Varnish determined the object was cacheable
} else {
set beresp.http.X-Cacheable = "YES";
}

# ....

return(deliver);
}

最佳答案

后端很可能会返回cookie,因此 Varnish 不会缓存内容。

这里是关于它的更多信息:Varnish-Cookies

您从LWP得到的响应也存在一些不一致之处。
实际上,我看到max-age header 设置为60秒,在后端的任何地方都看不到该 header 。

向源的LWP请求也可以帮助调试问题。

关于apache - Varnish :可缓存但未缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9341144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com