【问题标题】:Varnish cache only a specific url path清漆只缓存特定的url路径
【发布时间】:2015-07-11 14:25:04
【问题描述】:

我正在尝试使用 varnish 缓存 2 个网站:

  1. http://services.gradle.org
  2. http://nodejs.org/dist/

我配置了 2 个 DNS 条目:nodejs-proxy 和 gradle-proxy

在我的浏览器中,如果我访问 http://gradle-proxy,我会被重定向到 services.gradle.org 的清漆缓存网站。所以这部分有效。

但是,当我转到http://nodejs-proxy 时,如何配置它以使我的清漆机器只缓存和显示http://nodejs.org/dist/

我的 default.vcl 配置是:

backend gradle {
    .host = "207.223.250.8";
    .port = "80";
    .connect_timeout = 6000s;
    .first_byte_timeout = 6000s;
    .between_bytes_timeout = 6000s;
}

sub vcl_recv {
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.

   if (req.http.host == "gradle-proxy.corp.appdynamics.com") {
      set req.backend_hint = gradle;
   }

    if (! req.url ~ "^/dist/") {
        return(pass);
    }
    return(lookup);

}

谢谢

【问题讨论】:

    标签: caching proxy varnish varnish-vcl


    【解决方案1】:

    啊,我用 rm 搞定了这个:

    if (! req.url ~ "^/dist/") {
        return(pass);
    }
    return(lookup);
    

    并添加:

    sub vcl_recv {
        if (req.http.host == "nodejs-proxy") {
                set req.http.host = "nodejs.org";
                set req.url = regsub(req.url, "^", "/dist");
        }
    }
    
    backend nodejs {
        .host = "165.225.133.150";
        .port = "80";
        .connect_timeout = 6000s;
        .first_byte_timeout = 6000s;
        .between_bytes_timeout = 6000s;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      • 2017-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-25
      • 2012-09-20
      相关资源
      最近更新 更多