0

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;
}
2
  • Sounds like you're saying you want for Varnish to deliver content that it doesn't get the HTTP request for, since the content is in a domain other than the one Varnish is in front of? Can you clarify how you're expecting this to work? Dec 24, 2013 at 3:00
  • Please attach a varnishlog trace of the requests to see what's going on, your use case is fairly usual... Y suspect either the second domain is pointing to another ip or setting some cache hostile headers,
    – NITEMAN
    Dec 24, 2013 at 9:42

0

You must log in to answer this question.

Browse other questions tagged .