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 ...

Get Nginx Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.