From 54d4437c2fb636a754811c228011317928029ab7 Mon Sep 17 00:00:00 2001 From: AD7six Date: Mon, 30 Jan 2012 18:19:22 +0100 Subject: [PATCH] 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. --- nginx.conf | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/nginx.conf b/nginx.conf index 4d18daf..b9c5ddb 100644 --- a/nginx.conf +++ b/nginx.conf @@ -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 - #