我正在尝试使用 Varnish 来缓存2个网站:
我配置了2个DNS条目:nodejs-proxy和gradle-proxy
在我的浏览器中,如果我访问http://gradle-proxy,我将被重定向到services.gradle.org的 Varnish 缓存网站。因此,这部分工作。
但是,我该如何配置它,以便我的 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);
}
谢谢
最佳答案
嗯,我得到了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;
}
关于caching - Varnish 仅缓存特定的URL路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29992215/