Created
December 9, 2015 11:05
-
-
Save strebl/c85fe85f21294e05e194 to your computer and use it in GitHub Desktop.
caching & gzip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Gzip Settings | |
## | |
# Enable Gzip compressed. | |
gzip on; | |
# Compression level (1-9). | |
# 5 is a perfect compromise between size and cpu usage, offering about | |
# 75% reduction for most ascii files (almost identical to level 9). | |
gzip_comp_level 5; | |
# Don't compress anything that's already small and unlikely to shrink much | |
# if at all (the default is 20 bytes, which is bad as that usually leads to | |
# larger files after gzipping). | |
gzip_min_length 256; | |
# Compress data even for clients that are connecting to us via proxies, | |
# identified by the "Via" header (required for CloudFront). | |
gzip_proxied any; | |
# Tell proxies to cache both the gzipped and regular version of a resource | |
# whenever the client's Accept-Encoding capabilities header varies; | |
# Avoids the issue where a non-gzip capable client (which is extremely rare | |
# today) would display gibberish if their proxy gave them the gzipped version. | |
gzip_vary on; | |
# Compress all output labeled with one of the following MIME-types. | |
gzip_types | |
application/atom+xml | |
application/javascript | |
application/json | |
application/ld+json | |
application/manifest+json | |
application/rdf+xml | |
application/rss+xml | |
application/schema+json | |
application/vnd.geo+json | |
application/vnd.ms-fontobject | |
application/x-font-ttf | |
application/x-javascript | |
application/x-web-app-manifest+json | |
application/xhtml+xml | |
application/xml | |
font/eot | |
font/opentype | |
image/bmp | |
image/svg+xml | |
image/vnd.microsoft.icon | |
image/x-icon | |
text/cache-manifest | |
text/css | |
text/javascript | |
text/plain | |
text/vcard | |
text/vnd.rim.location.xloc | |
text/vtt | |
text/x-component | |
text/x-cross-domain-policy | |
text/xml; | |
# text/html is always compressed by HttpGzipModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cache.appcache, your document html and data | |
location ~* \.(?:manifest|appcache|html?|xml|json)$ { | |
expires -1; | |
access_log /var/log/nginx/static.log; | |
} | |
# Feed | |
location ~* \.(?:rss|atom)$ { | |
expires 1h; | |
add_header Cache-Control "public"; | |
} | |
# Media: images, icons, video, audio, HTC | |
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { | |
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"; | |
} | |
# WebFonts | |
# If you are NOT using cross-domain-fonts.conf, uncomment the following directive | |
location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ { | |
expires 1M; | |
access_log off; | |
add_header Cache-Control "public"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment