When writing dynamic web applications, we use nginx as a front-end web server and apache+mod_wsgi as an application server.
It is the job of nginx to:
- Handle SSL, and domain-level rewriting/redirects
- Handle static content (.jpeg, .png, .css, .js, .txt, .ico, .pdf, etc….)
- Handle dynamic downloads through X-Accel-Redirect
- Proxy other requests to apache
- Set the proper cache-control and expires headers on content
Ever run into the situation where you click log out, and then click the back button, and are still able to see the pages! That is bad. They are dynamic pages anyway, and should not be cached.
However, images, etc… SHOULD be cached. It is important that any references to images have a way to invalidate the cache. We append a number as a query string:
/path/to/script.js?192012129
This number is updated from time to time (via Python variable) when we need to invalidate the cache.
Anyway, here are some helpful nginx configuration directives.
# Send static requests directly back to the client location ~ \.(gif|jpg|png|ico|xml|html|css|js|txt|pdf)$ { root /path/to/document/root; expires max; } # Send the rest to apache location / { add_header Cache-Control 'no-cache, no-store, max-age=0, must-revalidate'; add_header Expires 'Thu, 01 Jan 1970 00:00:01 GMT'; proxy_pass http://127.0.0.1:8123; }