Anyone have VCL snippets of that configure Varnish to work with AIS? Typically Varnish should strip cookies on files and remove cookies Drupal doesn't need so that more is returned from cache. Is there a way to configure Varnish to work with this module or does it require no caching on these requests? Thanks.

Comments

spotzero’s picture

The cookie only maters if the path request path is "/files/styles/adaptive/", if the request unpath isn't that, its safe to remove all the cookies.

You could do something like this (warning, I just wrote this free hand, no guarantees that it compiles or works):

if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
  if (req.url ~ "/files/styles/adaptive/" && req.http.Cookie ~ "ais=") {
       // Since AIS is enabled, the adaptive style is being use and the ais cookie is set
       //  this request will return a 302 and not an image
       //  so either don't cache it and let the htaccess rule generate the redirect everytime
       // or clean up the cookie to only store the ais cookie and value and cache it.
  } else {
    unset beresp.http.set-cookie;
  }
}

Let me know what you end up with.

Thanks,

vinmassaro’s picture

It looks like your example is meant for vcl_fetch? I wasn't having any luck with it there.

Here is what worked for me in vcl_recv, by not caching ais paths. Thoughts?

  if (req.url ~ "(?i)\.(pdf|asc|dat|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|mp3|css|js)(\?.*)?$") {
    if (req.url ~ "/files/styles/adaptive/" && req.http.Cookie ~ "ais=") {
      return (pass);
    }
    else {
      unset req.http.Cookie;
    }
  }
spotzero’s picture

While there is some performance gain having Varnish cache the 302s, since the htaccess rules process the whole request and apache doesn't even run PHP, you're not missing out on much by not caching them.

Unless you've got a busy enough site that you have to worry about passing even those types of requests, it should be fine.

spotzero’s picture

Status: Active » Closed (fixed)
couloir007’s picture

I'm running varnish with ubuntu locally, and I can't this to work. Is this issue really resolved? It would be unfortunate that I can't use this because of varnish.

spotzero’s picture

Depends what you feel the solution should be.

The solution above was to simply tell varnish not to cache AIS's image style url at all. It works, but I'd liked to have had some fancy vcl that caches the adaptive style based on the ais cookie, though that's probably quite a complex solution.

Is the vcl code above not working for you?

couloir007’s picture

It's not. I'm not a varnish expert, so I'll come back to this is I really need to. I'm developing on ubuntu, but ultimately it will reside on centOS, so I may wait until I get to the centOS part.

Thanks!

stone_d’s picture

Issue summary: View changes

Hi there,

i got the same problem here. I wasn't sure why my site loads that long until i realized AIS isn't working anymore since having my site varnish-cached.
So: where do i have to put that code above in? Sorry - im not a varnish-expert ;)

Thanks in advance and regards,
F.