Improve static file caching

This commit is contained in:
Ashley Rich 2017-11-26 16:36:17 +00:00
parent c633ab9081
commit ca484fe861

View File

@ -1,32 +1,40 @@
# Don't cache appcache, document html and data. # Don't cache appcache, document html and data.
location ~* \.(?:manifest|appcache|html?|xml|json)$ { location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1; add_header Cache-Control "max-age=0";
} }
# Cache RSS and Atom feeds. # Cache RSS and Atom feeds.
location ~* \.(?:rss|atom)$ { location ~* \.(?:rss|atom)$ {
expires 1h; add_header Cache-Control "max-age=3600";
add_header Cache-Control "public";
} }
# Caches images, icons, video, audio, HTC, etc. # Caches images, icons, video, audio, HTC, etc.
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc)$ {
expires 1y; add_header Cache-Control "max-age=31536000";
add_header Cache-Control "public"; access_log off;
}
# Comment out these lines if you wish to record access/error logs for static files. # Cache svgz files, but don't compress them.
log_not_found off; location ~* \.svgz$ {
access_log off; add_header Cache-Control "max-age=31536000";
access_log off;
gzip off;
} }
# Cache CSS and JavaScript. # Cache CSS and JavaScript.
location ~* \.(?:css|js)$ { location ~* \.(?:css|js)$ {
expires 1y; add_header Cache-Control "max-age=31536000";
add_header Cache-Control "public"; access_log off;
}
# Cache WebFonts.
location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
add_header Cache-Control "max-age=31536000";
access_log off;
} }
# Don't record access/error logs for robots.txt. # Don't record access/error logs for robots.txt.
location = /robots.txt { location = /robots.txt {
log_not_found off;
access_log off; access_log off;
log_not_found off;
} }