Created
December 4, 2015 11:07
-
-
Save kilhage/7f0e7546457716dc9174 to your computer and use it in GitHub Desktop.
Enables gzip compression for common mime types in nginx
This file contains hidden or 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
# most people include something like this. don't. | |
# check your default nginx.conf, it's already covered in a much better way. | |
#gzip_disable "MSIE [1-6]\.(?!.*SV1)"; | |
# compress proxied requests too. | |
# it doesn't actually matter if the request is proxied, we still want it compressed. | |
gzip_proxied any; | |
# a pretty comprehensive list of content mime types that we want to compress | |
# there's a lot of repetition here because different applications might use different | |
# (and possibly non-standard) types. we don't really care, we still want them included | |
# don't include text/html -- it is always included anyway | |
gzip_types | |
text/css | |
text/plain | |
text/javascript | |
application/javascript | |
application/json | |
application/x-javascript | |
application/xml | |
application/xml+rss | |
application/xhtml+xml | |
application/x-font-ttf | |
application/x-font-opentype | |
application/vnd.ms-fontobject | |
image/svg+xml | |
image/x-icon | |
application/rss+xml | |
application/atom_xml; | |
# increase the compression level, at the expense of additional CPU | |
# cpu cycles are cheap virtually everywhere now, bandwidth not nearly as much | |
gzip_comp_level 9; | |
# the default is to gzip only HTTP 1.1 requests | |
# we want to gzip http 1.0 requests, too, so lower the level required | |
gzip_http_version 1.0; | |
# set the Vary: Accept-Encoding header to force proxies to store compressed and uncompressed versions | |
# per the nginx docs, a bug in IE 4 - 6 will cause them to not cache anything with this on | |
# most people aren't going to care about ie 6 anymore, but keep that in mind | |
gzip_vary on; | |
# increase the size of the buffers which hold responses to make sure larger content can be compressed too | |
# this means there are 16 buffers and they can each hold 8k | |
# if you serve a lot of ridiculously large text (like combined CSS) you might consider upping this slightly | |
gzip_buffers 16 8k; | |
# up the minimum length a little to account for gzip overhead | |
# this means anything smaller than 50 bytes won't be compressed. | |
# the default is 20 bytes, which is sooo tiny it's a waste to compress | |
gzip_min_length 50; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment