vcl - 如何不在 Varnish 中缓存 500 个内部服务器错误

标签 vcl varnish

在我的一生中,我无法弄清楚如何让 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]:

  • 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

    关于vcl - 如何不在 Varnish 中缓存 500 个内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16808767/

    相关文章:

    varnish - 如何让 Varnish 满足 Cloudcontrol 上静态文件的请求?

    c++builder - 如何在运行时在 C++ Builder XE7 中添加组件

    delphi - Delphi应用程序可以像Visual Studio一样有双快捷键吗? (即 Ctrl-k Ctrl-k)

    delphi - 如何解决XP中父窗体中Delphi子窗体不对齐的问题

    wordpress - varnish nginx wordpress ssl 几个域

    caching - 将beresp.ttl设置为0s是否会替换以前的缓存?

    c++ - 如何管理 Windows 文件打开对话框中的导航 Pane ?

    Delphi7 TeeChart v4 图例 - 如何滚动?

    php - 取消设置 php 中的变量会影响缓存吗?

    drupal - 表单 block 不适用于匿名用户