Reputation: 381
Im trying to use varnish to cache 2 websites:
I have 2 DNS entries configured: nodejs-proxy and gradle-proxy
In my browser, if I visit http://gradle-proxy, I get redirected to the varnish cached website for services.gradle.org. So this part works.
However, how can I configure it so my varnish machine only caches and display http://nodejs.org/dist/ when I go to http://nodejs-proxy?
my default.vcl configuration is:
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);
}
Thank you
Upvotes: 1
Views: 4067
Reputation: 381
Ah, I got this working by rm:
if (! req.url ~ "^/dist/") {
return(pass);
}
return(lookup);
and adding:
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;
}
Upvotes: 2