0

我有一个在 Apache 之前设置 Varnish 的服务器。我的 PHP 应用程序正在创建新文件以创建压缩的 JS 和 CSS 文件,但是在创建这些文件时,Varnish 3-4 分钟内看不到这些文件,因此第一个页面加载文件时出现 404 错误。我知道这些文件存在,因为我在文件系统中看到它们。

我应该如何解决这个问题?一些 htaccess 缓存标头可以提供帮助吗?

4

1 回答 1

1

您可以清除 VCL 上缓存的 404(带有特殊请求)[1],甚至强制完全不缓存 404 错误:

sub vcl_fetch {
  # ...
  if (beresp.status == 404) {
    set beresp.ttl = 0s;
    set beresp.http.cache-control = "no-cache, must-revalidate, post-check=0, pre-check=0";
  }
  # ...
}

[1] https://www.varnish-cache.org/docs/3.0/tutorial/purging.html

于 2013-10-04T19:52:52.557 回答