我正在尝试通过让 Varnish 继续提供这些页面的旧缓存版本(又名宽限模式)来解决后端服务器的问题,该服务器将不时开始提供具有 200 OK 响应的空白页面。
首先,我尝试检查 中的响应vcl_fetch
,但据我所知,没有办法确定 中的内容长度vcl_fetch
。然后我尝试在vcl_deliver
(Content-Length 标头可用的地方)进行这项工作。这确实有效,但我不知道如何删除坏的缓存对象(带有空白页的对象),所以这似乎是不行的。
有人建议我在 obj.grace 和 obj.ttl 中设置vcl_deliver
,这是我当前的代码:
sub vcl_deliver {
# If the front page is blank, invalidate this cached object, in hope
# that we'll get a new one.
if (req.url == "/" && std.integer(resp.http.content-length, 0) < 1000) {
set obj.grace = 0m;
set obj.ttl = 0m;
return(restart);
}
}
但是,Varnish 不喜欢这样,并且在我尝试加载 VCL 时给了我这个错误:
Message from VCC-compiler:
'obj.grace': cannot be set in method 'vcl_deliver'.
At: ('input' Line 146 Pos 9)
set obj.grace = 0m;
--------#########------
obj.ttl
如果我删除该行,我会得到同样的错误obj.grace
- 两者似乎都不可写入vcl_deliver
,即使文档另有说明。这是在清漆 3.0.2 上。