如何为通配符子域禁用varnish缓存

时间:2014-06-12 13:39:03

标签: regex caching varnish wildcard-subdomain varnish-vcl

我尝试在所有子域中禁用varnish中的缓存。我们的应用程序允许用户在我们网址的子域上创建和管理他们自己的网站,但是当他们尝试编辑页面时,清漆会一直缓存他们的网页。

我知道基本格式:

if (req.url ~ "[code here]") {
    # Don't cache, pass to backend
    return (pass);
}

但我尝试过的任何内容似乎都适用于所有子域名。

也许它是一个简单的正则表达式?

2 个答案:

答案 0 :(得分:2)

您可以将req.http.host用于此目的。是的,它可以是正则表达式。

sub vcl_recv
{
   /* your earlier definitions */
   if( req.http.host ~ 'my.subdomain.example.com' )
   {
        // set the backend first
        set req.backend = localhost;

        return( pass );

    }

    /* your definitions  */
 }

在某些情况下,您可能需要return( pipe )
https://www.varnish-cache.org/docs/2.1/faq/configuration.html

答案 1 :(得分:0)

我认为你需要这个任何子域名(注意这可能是一个问题,如果你使用www,因为它可能被认为是一个子域名),并将匹配之前的任何东西。在example.com中

sub vcl_recv {
      if(req.http.host ~ ".*\.example.com") {      
        return( pass );
    }

 }