Currently I manage to configure varnish to cache items from 1 user, but the when the second users comes in varnish fetch another asset from Apache.
How can I cache static assets behind magento ( css, js , image pdf etc ) accessible from multiple users ?
On vcl_recv, I've configured :
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
unset req.http.Https;
unset req.http.Cookie;
return (lookup);
}
On vcl_fetch :
if (beresp.status == 200 || beresp.status == 301 || beresp.status == 404) {
if (beresp.http.Content-Type ~ "text/html" || beresp.http.Content-Type ~ "text/xml")
{
# do something
} else {
unset beresp.http.expires;
unset beresp.http.set-cookie;
set beresp.ttl = 300h;
}
I suspect this this has something to do vcl_hash that store the cache with some kind of client's fingerprint.
Is there a way to manipulate the way it hash only for certain asset types ?
EDIT 1: Full config : http://pastebin.com/mzSVpEqN
As noted in the comments, comment out the
vcl_hash
function (provided you don't need it for anything else) and hopefully you should see improvements.HTH!
I found out the way to solve this.
Varnish store different cached page for each specific User-Agent. I found the following technique to normalize user agent ( https://www.varnish-cache.org/trac/wiki/VCLExampleNormalizeUserAgent )
I just put everything into 1 basket and see huge increase in the number of hits.
On vcl_recv:
Varnish will honor Vary headers from the backend. Unless the backend sends Vary: User-Agent, there's no reason to normalize the User-Agent client header.