4

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 http://example.com/?random

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.

1 Answer 1

8

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)

5
  • 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 Mar 26, 2013 at 12:46
  • I'm sorry, I misquoted -- one should use "" and not '' ... It compiles in my test.
    – Kvisle
    Mar 26, 2013 at 12:50
  • The double quotes do compile correctly, but the random link stay the same for me still. Mar 26, 2013 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, 2013 at 13:04
  • Yes, I think that fixed it up. Thanks Kvisle. (Giving you the check mark and voting up.) Mar 26, 2013 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .