【问题标题】:Serving /home cache to main-domain with Varnish使用 Varnish 将 /home 缓存服务到主域
【发布时间】:2014-08-21 08:29:12
【问题描述】:

我的应用程序的结构方式是,当您访问 www.example.com 时,您会被重定向到 www.example.com/home。所以,这意味着我在主域上什么都没有,只有一个将用户重定向到 /home 的文件。

我意识到 Varnish 正在缓存 www.example.com/home,因此当我访问 www.example.com 时,它不会为我提供缓存页面。我使用 www.example.com/home 对 Blitz 进行了压力测试,它运行良好。它可以轻松处理 300 个并发用户。但是当我测试 www.example.com 时,它会在最初的几秒钟内中断,这意味着它没有提供缓存页面。这是意料之中的,因为 Varnish 不知道我想为 /home 服务。

所以,我尝试了几种方法来“告诉” Varnish 在访问主域时为 /home 提供服务,但我无法正确处理。

我尝试使用“regsub”和“set req.http.host”规则作为下面的规则,但无法按照我需要的方式工作。如果有人能指出我正确的方向,我将不胜感激。

sub vcl_recv {

if (req.http.host == "example.com") {
                set req.http.host = "example.com";
                set req.url = regsub(req.url, "", "/home");
        }

}

谢谢!

【问题讨论】:

    标签: url-rewriting varnish vcl


    【解决方案1】:

    我终于找到了正确的代码来解决这个问题:

    if (req.http.host ~ "^" && req.url~ "/$") {
      set req.http.host = "^";
      set req.url = regsub(req.url, "/$", "/home");
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-13
      • 2016-12-11
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      • 2021-06-13
      相关资源
      最近更新 更多