清漆:仅缓存特定域 [英] Varnish: cache only specific domain

查看:22
本文介绍了清漆:仅缓存特定域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been Googling aggressively, but without luck.

我使用 Varnish 效果很好,但我想在单个服务器 (Apache) 上托管多个网站,而无需 Varnish 缓存所有网站.

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.

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

Can I specify what websites by URL to cache?

谢谢

推荐答案

(edited after comment) 这是 req.http.host,所以在你的 vcl 文件(例如 default.vcl)中:

(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;
   }
}

在 varnish3-vcl 中:

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);
   }
}

这篇关于清漆:仅缓存特定域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆