【问题标题】:How to NOT cache 500 Internal Server Errors in Varnish如何不在 Varnish 中缓存 500 个内部服务器错误
【发布时间】:2013-05-24 09:52:00
【问题描述】:

在我的一生中,我无法弄清楚如何让清漆忽略 500 个内部服务器错误的缓存。基本上,如果有人点击清漆并返回 500 内部服务器错误,我希望清漆不缓存该页面(设置 0s ttl/宽限期?)。我正在使用 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。

【问题讨论】:

    标签: vcl varnish


    【解决方案1】:

    默认情况下,Varnish 只会缓存以下状态码[1]:

    • 200:好的
    • 203:非权威信息
    • 300:多项选择
    • 301:永久移动
    • 302:暂时移动
    • 307:临时重定向
    • 410:走了
    • 404:未找到

    请注意,第一次成功发送页面时,您仍然会获得 MISS

    [1]http://book.varnish-software.com/3.0/VCL_Basics.html#the-initial-value-of-beresp-ttl

    【讨论】:

    猜你喜欢
    • 2012-09-25
    • 1970-01-01
    • 2023-04-05
    • 2019-01-17
    • 2011-10-17
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多