How to install and configure Nginx Brotli

How to install and configure Nginx Brotli

Brotli is developed by Google as an alternative to Gzip, Zopfli and Deflate, but we can say it’s enhancement.

Our case study on Brotli has shown compression ratios of more than 25% smaller than current methods, with less CPU usage.

Currently, Nginx does not have official support to Brotli.

But Google develop third-party on github called ngx_brotli that you can use on Nginx.

According to Brotli Github project descriptions, Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods.

It is similar in speed with deflate but offers more dense compression.

How to install Nginx Brotli module

Clone ngx_brotli from Github https://github.com/google/ngx_brotli

Check your Nginx version with command:

Now you need to download Nginx source, depend on your Nginx version.

In this example is Nginx 1.16.1, compile module and compiled Nginx Brotli located in objs.

Configure Nginx Brotli compression module

To load Brotli modules on Nginx, edit /etc/nginx/nginx.conf and add this code in top of configuration.

And on your server block add this code:

Check your Nginx configuration with

Now start your nginx and check Brotli sith CURL

You also can check online and compare Brotli compression vs Gzip compression on https://tools.paulcalvano.com/compression.php

Brotli vs Gzip Compression
Brotli vs Gzip Compression

You can see the result that HTML uncompressed size is 397.4 Kb, gzip compression size is 47.9 Kb and Brotli compression size is 38.8 Kb

Leave a Reply

Your email address will not be published. Required fields are marked *