add expire rules mimicking that of the apache config

These rules are closer to the expire logic defined for apache, and also
use a none-capturing regex which will be (unnoticably) faster.

Added a comment as to why there is no default expire header defined.
This commit is contained in:
AD7six 2012-01-30 18:19:22 +01:00
parent 703a75c229
commit 54d4437c2f
1 changed files with 32 additions and 12 deletions

View File

@ -101,24 +101,44 @@ http {
# Custom 404 page
error_page 404 /404.html;
# Static assets
location ~* ^.+\.(manifest|appcache)$ {
# No default expire rule. This config mirrors that of apache as outlined in the
# html5-boilerplate .htaccess file. However, nginx applies rules by location, the apache rules
# are defined by type. A concequence of this difference is that if you use no file extension in
# the url and serve html, with apache you get an expire time of 0s, with nginx you'd get an
# expire header of one month in the future (if the default expire rule is 1 month).
# Therefore, do not use a default expire rule with nginx unless your site is completely static
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html|xml|json)$ {
expires -1;
access_log logs/static.log;
}
# Set expires max on static file types (make sure you are using cache busting filenames or query params):
location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm)$ {
# This is pretty long expiry and assume your using
# cachebusting with query params like
# <script src="application.js?20110529">
#
# Just be careful if your using this on a frequently
# updated static site. You may want to crank this back
# to 5m which is 5 minutes.
expires 1M; # yes one month
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}
# Favicon
location ~* \.ico$ {
expires 1w;
access_log off;
add_header Cache-Control "public";
}
# Media: images, video, audio, HTC, WebFonts
location ~* \.(?:jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1Y;
access_log off;
add_header Cache-Control "public";
}
# opt-in to the future