Mastering Nginx

(Ron) #1
Chapter 5

[ 111 ]

Compressing


Compressing can be described with the following figure:


Optimizing for bandwidth can help reduce a response's transfer time. NGINX has


the capability of compressing a response it receives from an upstream server before


passing it on to the client. The gzip module, enabled by default, is often used on
a reverse proxy to compress content where it makes sense. Some file types do not


compress well. Some clients do not respond well to compressed content. We can
take both cases into account in our configuration:


http {

gzip on;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types text/plain text/css application/x-javascript text/
xml application/xml application/xml+rss text/javascript application/
javascript application/json;

gzip_disable msie6;

}

Here we've specified that we want files of the preceding MIME types to be compressed


at a gzip compression level of 2 if the request has come over at least HTTP/1.0, except
if the user agent reports being an older version of Internet Explorer. We've placed this


configuration in the http context so that it will be valid for all servers we define.

Free download pdf