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'm running a VPS with multiple different websites, and Varnish in front for caching. However, some websites should not be cached. Instead of making individual rules for each website, I would like to make a general "DON'T CACHE" list, which is linked to some rules. Possible?

In the following, I've sketched what I would like: a list of websites (ACL syntax) in the VCL configuration which should not be cached.

list cache_blacklist {
 "domain1.com";
 "domain2.com";
}

sub vcl_recv {
  if (req.http.host ~ cache_blacklist) {
    return(pass);
  }   
}

sub vcl_fetch {
  if (req.http.host ~ cache_blacklist) {
    return(hit_for_pass);
  }
}
share|improve this question
    
Nice question, I was thinking of the exact same thing, I thought of some kind of array option, but the list is much better. What's wrong with the code you gave here? Why doesn't it work? –  Saif Bechan Dec 21 '11 at 23:19
    
The list would need to be explicitly specified as 'acl', instead of 'list', but anyway I'm not sure varnish allows you to compare anything but against the client's IP address with an ACL anyway, so this wouldn't work even if the syntax was correct. –  JamesHannah Dec 22 '11 at 0:00
    
Thanks for your replies. "list"s doesn't exist in Varnish, so it throws a syntax error. I tried like JamesHannah suggested, to use acl cache_blacklist {} however, ACL will only match with client.id - not req.http.host. –  sqren Dec 22 '11 at 1:27

1 Answer 1

up vote 1 down vote accepted

First thing : you don't need to set a vcl_fetch rule if the condition depends on the request. Everything will be handled in vcl_recv.

vcl_fetch rules are only needed when condition depends on the server response.

HTTP Host being in the request...your vcl_fetch rule is actually useless.

Now that you don't need to tell "which domains should not be cached" twice, just use a single condition in vcl_recv like this :

sub vcl_recv {
    if (req.http.host == "domain1.com" || 
        req.http.host == "domain2.com") {
        return(pass);
    }
}

Note that you can also use regexp...not sure about which is the best...

share|improve this answer
    
Yes this is the way to go –  Saif Bechan Mar 31 '12 at 13:54

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.