IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    配置Varnish不缓存特定大小的内容

    root发表于 2011-12-07 10:32:29
    love 0

    最近使用的一台Varnish服务器,经常发现把内存资源和磁盘IO资源占满的情况,后面找原因,发现Varnish把一些大文件缓存了,例如一些压缩档。记得以前用Squid时是有相应设置项的,可以不缓存文件大小超过1M的文件。经过Google搜索了一番,发现有篇文章的方法不错,用变通的方法(vcl_fetch 不支持 pass 语法,但支持 restart)解决了我的困扰,遂写日志以记之。

    sub vcl_recv {
      /** ... vcl_recv example from above ... */
      /* Bypass cache for large files.  The x-pipe header is
         set in vcl_fetch when a too large file is detected. */
      if (req.http.x-pipe && req.restarts > 0) {
        remove req.http.x-pipe;
        return (pipe);
      }
      /** ... vcl_recv example from above ... */
    }
    sub vcl_fetch {
      /* Don't try to cache too large files.  It appears
         Varnish just crashes if we don't filter them. */
      if (beresp.http.Content-Length ~ "[0-9]{7,}") {
        set req.http.x-pipe = "1";
        return (restart);
      }
    }
    sub vcl_pipe {
      set bereq.http.connection = "close";
    }

    本文参考了:http://devblog.seomoz.org/2011/05/how-to-cache-http-range-requests/
    https://www.varnish-cache.org/lists/pipermail/varnish-misc/2010-November/004968.html



沪ICP备19023445号-2号
友情链接