perusio / drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
855 stars 246 forks source link

Boost never hit cached css/js #109

Open jimyhuang opened 11 years ago

jimyhuang commented 11 years ago

We've test drupal6_boost.conf. The problem is that all the static file deliver by this line first. Then the cached css never hit because it already there.

try_files $uri @cache;

That will cause css broken page when user visit cached page after some admin clear cache in drupal admin. We add a location block for css/js like this. Then

## Special case for css and boost
    location ~* ^.+\.(?:css|js)$ {
        access_log off;
        expires 30d;
        ## No need to bleed constant updates. Send the all shebang in one
        ## fell swoop.
        tcp_nodelay off;
        ## Set the OS file cache.
        open_file_cache max=3000 inactive=120s;
        open_file_cache_valid 45s;
        open_file_cache_min_uses 2;
        open_file_cache_errors off;

        ## Boost compresses can the pages so we check it. Comment it out
        ## if you don't have it enabled in Boost.
        gzip_static on;

        ## Error page handler for the case where $no_cache is 1. POST
        ## request or authenticated.
        error_page 418 = @no_cache;

        ## If $no_cache is 1 then it means that either we have a session
        ## cookie or that the request method is POST. So serve the dynamic
        ## page.
        if ($no_cache) {
            return 418; # I'm a teapot/I can't get no cachifaction
        }

        ## No caching for POST requests.
        if ($request_method = POST) {
            return 418;
        }

        # Now for some header tweaking. We use a date that differs
        # from stock Drupal. Everyone seems to be using their
        # birthdate. Why go against the grain?
        add_header Expires "Tue, 13 Jun 1977 03:45:00 GMT";
        # We bypass all delays in the post-check and pre-check
        # parameters of Cache-Control. Both set to 0.
        add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
        # Funny...perhaps. Egocentric? Damn right!;
        add_header X-Header "Boost 1.0";
        ## Boost doesn't set a charset.
        charset utf-8;

        # We try each boost URI in succession, if every one of them
        # fails then relay to Drupal.
        try_files /cache/perm/$host${uri}_.css /cache/perm/$host${uri}_.js /cache/$host/0$uri.html $uri =404;
    }