Varnish config to cache everything except a couple of pages

Events happening in the community are now at Drupal community events on www.drupal.org.
james_agnew's picture

Hello

Mercury 1.0 looking really good - nice work.

We have an anonymous website where we want everything to be cached by Varnish except

/somepage
/someotherpage

We set a couple of cookies (read by JS only, not Drupal) so I'd like to know whether we still need to strip these cookies via the.vcl file in order to force all pages to be cached?

Drupal users access the database via a different front end server that does not have Varnish running.

Thanks, James

Comments

Stripping non-essential cookies

joshk's picture

We set a couple of cookies (read by JS only, not Drupal) so I'd like to know whether we still need to strip these cookies via the.vcl file in order to force all pages to be cached?

Yes. Varnish (and the rest of the internet chain, including the end-user's browser) doesn't distinguish between cookies set by JS and those set by drupal, so if you have on-page scripts that set cookies — typical for analytics, mashups, etc — you will need to adjust your VCL file so that Varnish will ignore these when determining cacheability.

You can also take a more brute-force approach with your VCL (there's a lot of potential there) and implement logic that will cause all urls not matching your "somepage" criteria to strip all cookies and return a lookup. This could lead to some unexpected results (e.g. be sure there's NO use case where the content of those pages changes... drupal_set_messages won't get through, nor would anything else), but would be pretty bulletproof.

From https://wiki.fourkitchens.com/display/PF/Configure+Varnish+for+Pressflow

  // Cache all requests by default, overriding the
  // standard Varnish behavior.
   if (req.request == "GET" || req.request == "HEAD") {
     return (lookup);
   }

You could augment that if statement with something like && req.url ~ '^/(somepage|someotherpage)'. There's a ton of power in VCL.

Thanks

james_agnew's picture

I'll investigate further.

Mercury

Group organizers

Group categories

Post Type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: