Varnish: Remove all Cookies EXCEPT the ones you want

COO-KIES!

COO-KIES!

So, you’ve got a web server. It’s slow.

So, you optimize your app, and implement some caching. It’s faster, but not fast enough.

So, you decide to use Varnish, the popular reverse-proxy web application accelerator. It doesn’t work.

The reason it doesn’t work is that on your web site, you’ve got all kinds of Javascript-based goodies, like Google Analytics, or maybe embedded videos that set tracking cookies, or maybe things like AddThis that also set client-side cookies.

Well, client-side cookies are for the JS on your site; your application doesn’t actually care about them. BUT – and this is an annoying “but” – if those client-side cookies are set for “yourdomain.com”, then with every single request a reader makes to your server, those cookies are sent along.

And that means Varnish won’t cache anything, because it says, “Cookies?! EEK! No caching!”

So, how do you make Varnish happy with only the cookies that you want to keep?

Read on…

(more…)