Discourse behind Varnish?

Upgraded Varnish to V4, bringing with it some subtle but important VCL syntax changes. My Discourse block now looks like this, but it’s working only inconsistently:

    # Cache only the static assets in Discourse's' "assets" dir and pass everything else
    if (req.http.host ~"discourse.bigdinosaur.org") {
        if (req.url ~ "^/uploads/" ) {                              
            return (hash);
        }
        elseif (req.url ~ "^/assets/") {                              
            return (hash);
        }
        elseif (req.url ~ "^/user_avatar/") {                              
            return (hash);
        }
        else {
            return (pipe);
        }
    }

(lol hash pipe)

I’m seeing weirdly inconsistent cache hits and I have absolutely no clue why. Some objects that match the regexes above (like user avatars) are being cached, and some others (like…other user avatars) aren’t.

Haven’t really had the time yet to sit down and try to figure out what might be wrong or misconfigured, since switching over to varnish v4 meant putting out a bunch of other fires, but I’ll poke at it tomorrow, maybe.

6 Likes