Question

I want to implement varnish with my newly deployed rails web application.

Rails version 3.2.12 with

Ruby 1.9.2p318 (2012-02-14 revision 34678) [i686-linux]

In my application user authentication is done by cookies but varnish is not caching content when cookies are present there.So i found that for logged in users varnish is forwarding request to my application.i am vary new to varnish not sure how to solve this.May be i need to put some block in the vernish configuration file.But the thing is in live and users using my application.I had stopped the varnish.Any cocrete help will be appriciated really.

Was it helpful?

Solution

I found the solution in this blog Ruby on Rails, Varnish and user dependent content and i think the solution according to the blog is :

A good approach to get a simple solution to this problem is to add the application cookie to the hash Varnish uses to look for cached content. This is done in the vcl_hash function of the config file:

sub vcl_hash {
   if (req.http.Cookie ~ "your_application_cookie") {
     hash_data(req.url);
     hash_data(req.http.Cookie);
 return (hash);
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top