Avoiding Varnish Hitting Magento Cookies – VCL

cacheconfigurationmagentovarnish

Hello to serverfault users,

I would like to kindly ask someone to help me configure varnish for magento.

Using command: varnishtop -i TxHeader -I Cookie , following info show:

TxHeader Cookie: frontend=965b5...(*lots of numbers); adminhtml=3ae65...(*lots of numbers); EXTERNAL_NO_CACHE=1

"(*lots of numbers)" is just my adding to the info

How can I remove this cookies using Varnish VCL configuration to cache the page?

Thanks for any help in this case!, would be greatly appreciated!

Tomas

Best Answer

According to the Varnish-cache documentation you can use something like this. I've use similiar setups on other sites and it works like a charm!

sub vcl_recv {
  if (req.http.cookie) {
    set req.http.cookie = ";" + req.http.cookie;
    set req.http.cookie = regsuball(req.http.cookie, "; +", ";");
    set req.http.cookie = regsuball(req.http.cookie, ";(frontend|adminhtml|EXTERNAL_NO_CACHE)=", "; \1=");
    set req.http.cookie = regsuball(req.http.cookie, ";[^ ][^;]*", "");
    set req.http.cookie = regsuball(req.http.cookie, "^[; ]+|[; ]+$", "");

    if (req.http.cookie == "") {
      remove req.http.cookie;
    }
  }
}