【发布时间】:2014-09-16 04:13:46
【问题描述】:
我的 varnish (v3.0.2) 缓存一直存在问题,尽管 TTL 为 24 小时,但它在不到 60 秒后不断重置对象的缓存、cookie 被剥离、内容编码标准化、非关键标头未设置,Cache-Control 设置为 public,s-maxage=86400 等。
由于某种原因,如果您在一分钟内反复访问以下 URL,您会看到 Age 逐渐上升,然后达到零(X-Cache 返回 MISS):
http://data.eyewire.org/volume/83329/chunk/0/1/0/1/tile/xz/32:64
没有 n_lru_nuked 对象,缓存超过 60GB。我看了清漆日志,可能已经看到了 ExpBan 的一些情况,但我终其一生都无法弄清楚原因。
以下是我的 vcl 文件的一些关键部分:
sub vcl_recv {
set req.grace = 120s;
# normalize Accept-Encoding to reduce vary
if (req.http.Accept-Encoding) {
if (req.http.User-Agent ~ "MSIE 6") {
unset req.http.Accept-Encoding;
}
elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
}
elsif (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
}
else {
unset req.http.Accept-Encoding;
}
}
# This uses the ACL action called "purge". Basically if a request to
# PURGE the cache comes from anywhere other than localhost, ignore it.
if (req.request == "PURGE")
{if (!client.ip ~ purge)
{error 405 "Not allowed.";}
return(lookup);}
if (req.http.Upgrade ~ "(?i)websocket") {
return (pipe);
}
# ....
if ( req.http.host ~ "data\.eyewire\.org" ) {
unset req.http.Cookie;
unset req.http.Accept-Language;
unset req.http.Expires;
unset req.http.Cache-Control;
unset req.http.User-Agent;
return(lookup);
}
# ....
}
sub vcl_fetch {
# ....
if ( req.http.host ~ "data.eyewire.org" ) {
if ( req.url ~ "^/volume" ) {
unset beresp.http.Set-Cookie;
set beresp.ttl = 24h;
set beresp.http.Cache-Control = "public, s-maxage=86400";
set beresp.http.X-TTL = beresp.ttl;
return(deliver);
}
elsif (req.url ~ "^/cell") {
set beresp.ttl = 1h;
return(hit_for_pass);
}
}
}
# from http://blog.bigdinosaur.org/adventures-in-varnish/
sub vcl_pass {
set bereq.http.connection = "close";
if (req.http.X-Forwarded-For) {
set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
}
else {
set bereq.http.X-Forwarded-For = regsub(client.ip, ":.*", "");
}
}
# from http://blog.bigdinosaur.org/adventures-in-varnish/
sub vcl_pipe {
#we need to copy the upgrade header
if (req.http.upgrade) {
set bereq.http.upgrade = req.http.upgrade;
set bereq.http.connection = req.http.connection;
}
set bereq.http.connection = "close";
if (req.http.X-Forwarded-For) {
set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
}
else {
set bereq.http.X-Forwarded-For = regsub(client.ip, ":.*", "");
}
}
# from http://blog.bigdinosaur.org/adventures-in-varnish/
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
# from http://blog.bigdinosaur.org/adventures-in-varnish/
sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
sub vcl_deliver {
# Display hit/miss info
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
set resp.http.X-Cache-Hits = obj.hits;
}
else {
set resp.http.X-Cache = "MISS";
}
# Security Non-Disclosure
remove resp.http.X-Varnish;
remove resp.http.X-Powered-By;
remove resp.http.Server;
return(deliver);
}
谢谢!
编辑:仅供参考:我不得不恢复对 VCL 的一些更改以解决生产中的问题,但问题仍然基本相同。
【问题讨论】:
-
如果这实际上是正在使用的 VCL,我发现响应中不存在 X-TTL 很奇怪......在您到达主机 if 子句之前可能会有返回吗? (#....我猜表示你认为没有播放的内容)
-
嘿克拉伦斯,很抱歉我应该重新添加该部分。当我回滚 VCL 时,我恢复了一些调试信息。但是,我可以毫无问题地添加 VCL 交付部分。现在让我这样做。
-
您能否确认没有外部进程对内容发出 PURGE 请求?如果内容没有被 LRU nuke 驱逐,那么它很可能被从缓存中清除/禁止。
标签: caching varnish varnish-vcl