清漆缓存仅特定的URL路径

时间:2015-05-01 17:51:24

标签: caching proxy varnish varnish-vcl

我尝试使用清漆来缓存2个网站:

  1. http://services.gradle.org
  2. http://nodejs.org/dist/
  3. 我配置了2个DNS条目:nodejs-proxy和gradle-proxy

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

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

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

    谢谢

1 个答案:

答案 0 :(得分: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;
}