Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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);
}
share|improve this question
    
What have you tried so far? –  Pothi Nov 6 '13 at 2:29

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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