Caching static assets if present

Adam Zell zellster at
Wed Sep 3 03:03:34 MSD 2008


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|/ {
  rewrite ^/[|]dynamic[|](.*) $1;

  # ... various proxy settings

  proxy_pass http://back-end <http://zope-consumer>;

Is there a cleaner way to do this?


zellster at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list