Caching static assets if present

Hello,

I am configuring an environment where at deployment-time static files
are
identified and stored in a known location. Also as part of deployment,
each
static file has a compressed version generated, and touch’ed with the
same
times as the source file (e.g. touch --reference=foo.js foo.js.gz).

The one interesting requirement that did not seem straight-forward is
that I
want to pass the URL to the back-end if the static file could not be
found
(instead of returning a 404). This should be a rare occurrence and can
be
tracked through the nginx logs.

What I have looks like:

location / {

… various proxy settings

proxy_pass http://back-end http://zope-consumer/;
}

location ^~ /static/ {
alias /opt/nginx/assets/static/;

expires max;
gzip_static on;

error_page 404 = /|dynamic|$uri;
}

location ^~ /|dynamic|/ {
internal;
rewrite ^/[|]dynamic| $1;

… various proxy settings

proxy_pass http://back-end http://zope-consumer;
}

Is there a cleaner way to do this?

Thanks,

Hello,

On Tue, Sep 2, 2008 at 5:55 PM, Maxim D. [email protected] wrote:

Hello!

}

Maxim D.

Great, thank you for the pointer. Is this location feature documented
anywhere on the wiki?

Hello!

On Tue, Sep 02, 2008 at 04:03:34PM -0700, Adam Z. wrote:

tracked through the nginx logs.
alias /opt/nginx/assets/static/;

… various proxy settings

proxy_pass http://back-end http://zope-consumer;
}

Is there a cleaner way to do this?

Named locations was introduced specially for such things. Try the
following:

location /static/ {

error_page 404 = @fallback;
}

location @fallback {
proxy_pass …;
}

Maxim D.