Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Server setup: Ubuntu 12.10, Varnish 3.0.2, Nginx 1.3.14, with a WordPress 3.5.1 install.

We are using the "Random Redirect" plugin which shows a random blog post at the URL

I would like to set Varnish to not cache the above URL, since currently the "random" post keeps showing the same post.

A specific snippet to show what to put in default.vcl would be super helpful. Thanks.

share|improve this question
up vote 2 down vote accepted

Putting the following block in vcl_recv should do it:

if ( req.url ~ "^/\?random" ) {
  return (pass);

When you return(pass), you will jump past the opportunity to look up the request in the cache.

The default behavior is to do a bunch of tests to see if it is likely that the content is dynamic (does it set cookies, does it require authentication, is it a POST-request, things like that) - if none of those conditions are met, Varnish falls back to return(lookup)

share|improve this answer
I tried almost the exact code before posting my question and it didn't work. I tried your code and it also didn't work. I got the following errors: Command failed with error code 106 Message from VCC-compiler: Syntax error at ('input' Line 48 Pos 16) if ( req.url ~ '^/?random' ) { ---------------#-------------- Running VCC-compiler failed, exit 1 VCL compilation failed – Kevin Worthington Mar 26 '13 at 12:46
I'm sorry, I misquoted -- one should use "" and not '' ... It compiles in my test. – Kvisle Mar 26 '13 at 12:50
The double quotes do compile correctly, but the random link stay the same for me still. – Kevin Worthington Mar 26 '13 at 12:58
I forgot to add escaping of the ?, since it was interpreted as a part of the regular expression. Again, sorry about that. – Kvisle Mar 26 '13 at 13:04
Yes, I think that fixed it up. Thanks Kvisle. (Giving you the check mark and voting up.) – Kevin Worthington Mar 26 '13 at 13:12

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.