在我的一生中,我无法弄清楚如何让 varnish 忽略 500 个内部服务器错误的缓存。基本上,如果有人点击 varnish 并返回 500 内部服务器错误,我希望 varnish 不缓存该页面(设置 0s ttl/grace period?)。我正在使用 Varnish 3.0.3,这是我的 VCL。默认情况下,我想将页面缓存 30 天。
sub vcl_fetch {
# Set 30-day TTL
set beresp.ttl = 2592000 s;
set beresp.grace = 15d; /* The max amount of time to keep object in cache */
if (beresp.status == 301 || beresp.status == 302) {
return (hit_for_pass);
}
# Serve pages from the cache should we get a sudden error and re-check in one minute
if (beresp.status >= 500) {
set beresp.grace = 1s;
set beresp.ttl = 1s;
return (hit_for_pass);
}
# Unset the "etag" header (suggested)
unset beresp.http.etag;
return(deliver);
}
所以,用英语来说:如果返回一个 500 内部服务器...... X-CACHE 应该显示一个 MISS。当我刷新页面时,如果它仍然是 500 个内部服务器,那么它应该再次显示一个 MISS。如果页面成功传送,它应该显示一个 HIT。
最佳答案
默认情况下,Varnish 只会缓存以下状态代码 [1]:
请注意,第一次成功交付页面时,您仍然会收到 MISS
[1] http://book.varnish-software.com/3.0/VCL_Basics.html#the-initial-value-of-beresp-ttl
关于vcl - 如何不在 Varnish 中缓存 500 个内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16808767/