Varnish:仅缓存特定域

发布于 2024-09-19 11:02:55 字数 141 浏览 8 评论 0原文

我一直在积极地谷歌搜索,但没有运气。

我使用 Varnish 取得了很好的效果,但我想在单个服务器 (Apache) 上托管多个网站,而不用 Varnish 缓存所有网站。

我可以通过 URL 指定要缓存的网站吗?

谢谢

I have been Googling aggressively, but without luck.

I'm using Varnish with great results, but I would like to host multiple websites on a single server (Apache), without Varnish caching all of them.

Can I specify what websites by URL to cache?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑饮青盏花 2024-09-26 11:02:55

(评论后编辑) 它是 req.http.host,因此在您的 vcl 文件(例如 default.vcl)中执行:

sub vcl_recv {
  # dont cache foo.com or bar.com - optional www
   if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
     pass;
   }
  # cache foobar.com - optional www
   if (req.http.host ~ "(www\.)?foobar\.com") {
     lookup;
   }
}

在 varnish3-vcl 中:

sub vcl_recv {
  # dont cache foo.com or bar.com - optional www
   if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
     return(pass);
   }
  # cache foobar.com - optional www
   if (req.http.host ~ "(www\.)?foobar\.com") {
     return(lookup);
   }
}

(edited after comment) It's req.http.host, so in your vcl file (e.g. default.vcl) do:

sub vcl_recv {
  # dont cache foo.com or bar.com - optional www
   if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
     pass;
   }
  # cache foobar.com - optional www
   if (req.http.host ~ "(www\.)?foobar\.com") {
     lookup;
   }
}

And in varnish3-vcl:

sub vcl_recv {
  # dont cache foo.com or bar.com - optional www
   if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
     return(pass);
   }
  # cache foobar.com - optional www
   if (req.http.host ~ "(www\.)?foobar\.com") {
     return(lookup);
   }
}
猥︴琐丶欲为 2024-09-26 11:02:55

是的,

在 vcl_recv 中,您只需匹配您不希望缓存并传递它们的主机。像这样的东西(未经测试):

vcl_recv {
   # dont cache foo.com or bar.com - optional www
   if (req.host ~ "(www)?(foo|bar).com") {
     return(pass);
   }
}

Yes,

in vcl_recv you just match the hosts that you would like not to cache and pass them. Something like this (untested):

vcl_recv {
   # dont cache foo.com or bar.com - optional www
   if (req.host ~ "(www)?(foo|bar).com") {
     return(pass);
   }
}
内心激荡 2024-09-26 11:02:55

对于 Varnish 4,

将查找替换为 hash

default.vcl:

sub vcl_recv {
  # dont cache foo.com or bar.com - optional www
   if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
     return(pass);
   }
  # cache foobar.com - optional www
   if (req.http.host ~ "(www\.)?foobar\.com") {
     return(hash);
   }
}

For Varnish 4

replace lookup with hash

default.vcl:

sub vcl_recv {
  # dont cache foo.com or bar.com - optional www
   if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
     return(pass);
   }
  # cache foobar.com - optional www
   if (req.http.host ~ "(www\.)?foobar\.com") {
     return(hash);
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文