0

I would like to set up Varnish as reverse proxy cache for Apache.

How can setup Varnish so that Varnish should serve all static data (jpeg, jpg, png, gif, ico, js, css, txt, pdf, gz, zip, lzma, bz2, tgz, tbz, webp, html, htm) and A dynamic pages should be handed to Apache)

The only suggestions I have seen so far, are some variation of putting all my static content in a different place (e.g. subdomain) from the dynamic content. This seems odd, even ridiculous. Eitherway, that's not really an option.

Would something like this help?

if (req.url ~ “\.(jpeg|jpg|png|gif|ico|webp|js|css|txt|pdf|gz|zip|lzma|bz2|tgz|tbz|html|htm)$”) {
return (lookup);
} else {
return (pass);
}
2

Basically you can intercept in Varnish content by extension:

sub vcl_recv {
  //...
  if (req.url ~ "(?i)\.(jpeg|jpg|png|gif|ico|webp|js|css|txt|pdf|gz|zip|lzma|bz2|tgz|tbz|html|htm)$") {
      unset req.http.Cookie;
      return (lookup);
  } else {
      return (pass);
  }
  //...
}

// ..

sub vcl_fetch {
  //...
  if (req.url ~ "(?i)\.(jpeg|jpg|png|gif|ico|webp|js|css|txt|pdf|gz|zip|lzma|bz2|tgz|tbz|html|htm)$") {
      unset beresp.http.set-cookie;
  }
  //...
}

Keep in mind you have to strip cookies from static content.

0

A quick google search found the following solution:

Your best bet would be to move your static content to a new domain with a different IP. You would then just call it form there

Here is the link to the whole post: https://www.varnish-cache.org/forum/topic/56

Basically you would point your Varnish server at the static content and let Apache point to the dynamic contents IP.

  • I should have specified more clearly - this solution (cache by location) is not really an option – OC2PS Nov 5 '13 at 23:45
  • @OC2PS Why is it not an option? – Raffael Luthiger Nov 7 '13 at 0:05
  • Because the data are not separated out neatly into static and dynamic folders. – OC2PS Nov 7 '13 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.