0

Varnish 脚本对于 vcl 来说似乎相当健壮,但我还不知道如何让它做我需要的。我从同一个代码库运行不同的站点,我希望为大多数目录提供统一的清漆缓存,所以

x.mysite.org/theme/something.gif 和 y.mysite.org/theme/something.gif 不应在清漆缓存中存储相同 gif 的两个副本

然而

x.mysite.org/file.php/1 和 y.mysite.org/file.php/1 应该根据 url 有单独的缓存。

mysite.org 也是一个拥有自己缓存的其他站点。

我目前的方向如下

sub vcl_fetch {
  if (req.url ~ ".*\.org/file\.php") {
    # do normal site specific caching
  } elseif (req.url ~ "^+?\.mysite.org") {
    # cache all found material in a base directory so everyone knows where to look
    set req.url = regsub(req.url, "(.*\.org)(.*)", "base.mysite.org\2");
  } else {
    # do normal site specific caching for base site
  }
}

sub vcl_recv {
  # do I need to do something here to look in base.mysite.org
}

如有必要,我可以使 base.mysite.org 成为真正的 apache 服务站点,这样如果没有缓存,请求就会失败。

我在写路径上吗,有什么帮助。

4

2 回答 2

1

你应该规范化req.http.host而不是req.url,所以

sub vcl_fetch {
  # if it starts with /theme or /static, or contains .gif,.png etc, 
  #   then consider the host to the normalized/common host
  if (req.url ~ "^/(theme|static)" || req.url ~ "\.(gif|png)" ) {
    set req.http.host = "base.mysite.org";
    return (lookup);
  }
  # else, do non shared stuff here
}
于 2012-01-06T20:43:27.080 回答
0

默认情况下,Varnish 将使用主机名 + URL 来获取缓存对象的哈希值。这意味着即使 x.mysite.org/theme/something.gif 和 y.mysite.org/theme/something.gif 指向完全相同的内容,Varnish 也会将它们视为两个不同的缓存对象。使它们指向同一个缓存对象的唯一方法是规范化主机名,正如 Ivy 在他的帖子中解释的那样。

'希望有帮助。

于 2012-02-04T21:10:32.040 回答