Varnish Purge-浏览器硬刷新

Varnish Purge-浏览器硬刷新

我们使用 varnish 代理/缓存运行 drupal 的 2 个 Web 服务器上的内容。话虽如此,一切似乎都正常且井然有序,页面正在缓存,drupal 能够发出清除请求等等。但是,我们发现一个奇怪的问题,当您打开页面并进行硬刷新(shift+refresh)时,我们会收到“Error 200 Purged”的报告。这只发生在硬刷新时。后续刷新将使页面恢复。

根据通用文档,配置是一个简单的清除块。我们可能在这里做错了什么,以至于硬刷新导致了这个错误?

# Allow purging
if (req.method == "PURGE") {
    if (!client.ip ~ purge) {
        # Return Error 405 if not allowed.
        return (synth(405, "Forbidden - Not allowed."));
    }

   return (purge);
}

按 shift+刷新时出错:

错误 200 已清除

提前感谢您对此事的任何指导。

答案1

在 Varnish IRC 频道上与 Reza 交谈后,我发现其中有一段代码既有问题又不安全。这段代码是:

if (req.http.Cache-Control ~ "(?i)no-cache") {
   # http://varnish.projects.linpro.no/wiki/VCLExampleEnableForceRefresh
   # Ignore requests via proxy caches and badly behaved crawlers
   # like msnbot that send no-cache with every request.
       if (! (req.http.Via || req.http.User-Agent ~ "(?i)bot" || req.http.X-Purge)) {
           #set req.hash_always_miss = true; # Doesn't seems to refresh the object in the cache
           return(purge); # Couple this with restart in vcl_purge and X-Purge header to avoid loops
       }
   }

删除后,一切正常。谢谢 Reza

相关内容