Book Image

Nginx Essentials

By : Valery Kholodkov, Valery I Kholodkov
Book Image

Nginx Essentials

By: Valery Kholodkov, Valery I Kholodkov

Overview of this book

Table of Contents (13 chapters)

Enabling response compression


Performance of your website can be improved by enabling response compression using GZIP. Compression reduces the size of a response body, reduces the bandwidth required to transfer the response data, and ultimately makes sure the resources of your website are delivered to the client side sooner.

Compression can be enabled using the gzip directive:

location / {
    gzip on;
    [...]
}

This directive is valid in the http, server, location, and if sections. Specifying off as the first argument of this directive disables compression in the corresponding location if it was enabled in outer sections.

By default, only documents with MIME type text/HTML are compressed. To enable compression for other types of documents, use the gzip_types directive:

location / {
    gzip on;
    gzip_types text/html text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    [...]
}

The preceding configuration enables compression for MIME...