Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to configure varnish not to cache any domain that begins with "staging" using the pass method like so:

if( req.url ~ "^(staging.)" )

I suspect I'm using VCL selectors wrong but after looking around on the n

share|improve this question

If you'd like Varnish "not to cache" and "not to look up in the cache", then the following should work...

# not to look up in the cache
sub vcl_recv {
  if( ~ "^staging" ) {
    return( pass );

  # other directives

# not to cache
sub vcl_fetch {
  if( ~ "^staging" ) {
    return( hit_for_pass );

For more info, checkout a similar solution from the official book on Varnish.

share|improve this answer

req.url doesn't have that information. Try using req.http.Host instead?

share|improve this answer
Tried that as well with: if (req.http.Host ~ "^(staging.)^") { return (pass); } Still no luck. – Will Sep 17 '13 at 0:40
@Will it should be if (req.http.Host ~ "^(staging.)") { return (pass); } . There is an extra ^ symbol in it. Please check my alternative answer to see if that helps! – Pothi Sep 17 '13 at 1:47

Your Answer


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.