How to set Varnish so that it doesn't cache a specific URL with a query string?
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.
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)