Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
You're right about vcl_hash. Post your vcl_hash portion as well, or if it is ok with you, post your entire vcl file. –  KM. Mar 1 '12 at 2:57
    
Full config added. –  Rianto Wahyudi Mar 1 '12 at 4:55
    
Yeah, you are hashing data per host or ip depending on your conditions, so content is cached for users whose browsing meets those conditions. Comment out the vcl_hash function as see what you get. –  KM. Mar 1 '12 at 15:13
    
Also, do you need the vcl_hash function for something else? –  KM. Mar 1 '12 at 15:22
    
At this point I dont need vcl_has to do anything else. –  Rianto Wahyudi Mar 2 '12 at 2:33

3 Answers 3

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!

share|improve this answer
    
I've tried this but it doesn't help. Is there anyway to print out the hash value? –  Rianto Wahyudi Mar 3 '12 at 7:03
    
Start by examining what is being sent to the backend, especially cookies: varnishtop -i TxHeader -I Cookie –  KM. Mar 3 '12 at 13:49
    
Thanks KM01 .. Your suggestion point me to the right direction. –  Rianto Wahyudi Mar 5 '12 at 21:57
up vote 0 down vote accepted

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:

if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
     set req.http.user-agent = "Mozilla";
     unset req.http.Https;
     unset req.http.cookie;
     return (lookup);
}
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.