We're using Varnish 3.0.3.
The web site serves images from two domains. Images that have the same URL as the site's domain are cached successfully and are served via Varnish. Images coming from a different domain are ignored. We would like all images delivered via Varnish regardless of where they are coming from.
I've tried the two approaches. These are two very simple Varnish configurations. These two configurations work, but images from the second domain are ignored by Varnish. When I watch the activity for the browser, it is making a request directly to the second domain for those images instead being delivered by Varnish.
The backend has all the images for both domains. The web site is just coded to retrieve the images with two different domains. I cannot change the code of the web site to use one domain.
A similar scenario would be if our web site pulled images from our Flickr account or pulled images from a CDN. Would it be possible to have Varnish cache and deliver those images too? I understand that we would specify another backend, but in my testing I cannot get anything other than the primary domain to be delivered by Varnish.
The purpose behind this is to serve as a region edge location. The Varnish server should serve all content instead of the visitor pulling content from different sources/domains.
1.
backend default {
.host = "192.168.1.1";
.port = "http";
}
sub vcl_recv {
if (req.url ~ "\.(gif|jpg|jpeg|png)$") {
unset req.http.cookie;
unset req.http.Accept-Encoding;
unset req.http.Vary;
set req.backend = default;
return(lookup);
}
}
sub vcl_fetch {
set beresp.ttl = 24h;
set beresp.grace = 23h;
}
2.
backend default {
.host = "192.168.1.1";
.port = "http";
}
sub vcl_recv {
#Primary domain of site
if (req.http.host == "www.domain.com") {
set req.backend = default;
return (lookup);
#Domain where images are stored
} elsif (req.http.host == "www.domain2.com") {
set req.backend = default;
return (lookup);
}
}
sub vcl_fetch {
set beresp.ttl = 24h;
set beresp.grace = 23h;
}