我在开发服务器上运行了varnishsetup(Varnish 3),并在生产服务器上运行相同的设置。 除非我对它进行测试,否则开发服务器不会获得任何流量。 生产服务器通过该varnishinstance获得大约80个网站的大量流量。网站是完全相同的,因此所有这些网站的VCL都很好。
目前我正在使用URL智能禁令和ban_lurker进行测试。
我期待的是,当我添加禁令时,即使禁令因某些原因无效,它也应该留在禁令列表中,仅用于我的缓存+后端响应宽限期中最大的TTL。
问题
问题是,在我的produserver上,禁令永远停留在禁令列表中(至少24小时以来,我已经把它放弃了)。
所以我调整了我的VCL,以便我可以预期任何缓存对象都不可能在缓存中停留超过20分钟,因为我强制从我的vcl_fetch开始20分钟并强制beresp.grace为0
在我的开发varnishserver上,这似乎与此完全相同。当我点击网站并缓存一些东西时,然后禁止进入,它会在20分钟内消失。 在我的生产服务器上,这似乎对banlist没有任何影响。它就在那里。
我想念那里的东西吗?
VCL
有人可以看看我的VCL并告诉我我做错了什么吗? 请注意,我省略了一些像后端配置和清除/禁用配置的东西,因为我觉得现在没关系。如果我错了,请纠正我:)
import std;
# Define backends
include "backends.vcl";
# Define recv basics
sub vcl_recv {
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE" &&
req.request != "PURGE" &&
req.request != "BAN") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
}
# Define purging and banning rules
include "purging-banning.vcl";
# Appart from PURGE and BAN requests, we only handle GET and HEAD requests
sub vcl_recv {
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
# Never cache monitor.php
if (req.url ~ "^/monitor.php") {
return (pass);
}
# in case of down backends serve content up to 30 minutes old
if (req.backend.healthy) {
set req.grace = 2m;
} else {
set req.grace = 30m;
}
}
# Define purging and banning rules
include "recv-url-rules.vcl";
# If the URL's hasn't been caught by recv-url-rules.vcl, continue with common rules
sub vcl_recv {
# Don't cache AJAX requests
if (req.http.X-Requested-With == "XMLHttpRequest") {
return(pass);
}
}
sub vcl_fetch {
# Set default TTL of 20 minutes
set beresp.ttl = 20m;
# Keep objects in cache beyond their lifetime
set beresp.grace = 0s; # for testing purposes
# Don't cache if requested so by the server
if (beresp.http.X-NoCache == "no-cache" || beresp.http.cache-control ~ "private") {
set beresp.ttl = 0s;
set beresp.http.Cache-Control = "max-age = 0";
return ( hit_for_pass );
}
# Pass (don't cache) big files (limit is just under 1MB)
if ( beresp.http.Content-Length ~ "[0-9]{6,}" ) {
set beresp.ttl = 0s;
return ( hit_for_pass );
}
# Remember URL and HOST for the ban-lurker
set beresp.http.x-url = req.url;
set beresp.http.x-host = req.http.host;
}
sub vcl_deliver{
# These were set for the ban-lurker, but don't have to be send to the client
unset resp.http.x-url;
unset resp.http.x-host;
# Add a header to the request so that we can see wether or not the object came from cache
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
sub vcl_pipe {
# http://www.varnish-cache.org/ticket/451
# This forces every pipe request to be the first one.
set bereq.http.connection = "close";
}
清漆文档
Varnish文档声明如下:
在Varnish运行vcl_fetch之前,beresp.ttl变量已经设置为一个值。 >它将使用它找到的第一个值:
Cache-Control响应头中的s-maxage变量 Cache-Control响应头中的max-age变量 Expires响应标头 default_ttl参数。
在某些情况下,后端响应是否仍有可能覆盖TTL?即使我强制它在vcl_fetch中?
答案 0 :(得分:4)
禁令将保留在禁止列表中,直到缓存中所有早于它的对象都已经过检查。如果您使用长TTL提供长尾内容,则该禁令将会持续很长时间。
然而,由于禁令仅针对每个对象进行一次评估,因此实际上没有任何缺点(除了美学)。别担心。