Previously, we talked about various new methods for speed-up Nginx. Nginx Brotli Compression is a Modern Loseless Compression Algorithm Like gzip. ngx_brotli is a Set of 2 Nginx Modules. Nginx Brotli was not discussed so far as it was not exactly stable. Replacing gzip deflate with Nginx Brotli Compression typically gives an increase of 20% in compression density for text files, while compression and decompression speeds are roughly unchanged. Streams compressed with Brotli have the proposed content encoding type “br”.
Nginx Brotli Compression : Basic Details of Module
Brotli library and Nginx Brotli module are under active development. Brotli is a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling. It offers more dense compression than gzip.
ngx_brotli
is a set of two nginx modules. ngx_brotli filter
module is used to compress responses on-the-fly,
ngx_brotli static
module used to serve pre-compressed files. Brotli format was developed by Google as Open Source development and has been refined now. Brotli and gzip deflate are very closely related. Both uses a sliding window for backreferences. Gzip uses a fixed 32KB window. While Brotli can use window size from 1KB to 16MB.
Other differences include smaller minimal match length (2 bytes vs 3 bytes), larger maximal match length (16779333 bytes vs 258 bytes).
At time of first publication of this guide, Nginx Brotli Compression is not exactly what is exactly to jump right now for a production server. Testing on test server is suggested. Here is benchmarking – https://blog.quickmediasolutions.com/2015/09/22/benchmarking-brotli.html
. You can test community.centminmod.com
‘s server with cURL :
---
1 |
curl -vso /dev/null -H"Accept-Encoding: gzip, br" https://community.centminmod.com/ |

Deploying Nginx Brotli Compression
Official repository is here —
1 |
https://github.com/google/ngx_brotli |
As with the newer Nginx versions we can add modules easily, but typically Nginx Brotli needs compilation, we are describing all the steps :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
apt-get install python2.7 python-dev cd /opt git clone https://github.com/google/brotli.git && cd brotli sudo python setup.py install cd tests sudo make # we now have a ‘bro’ executable in the brotli/tools/ dir cd /opt # we'll instal Libbrotli wrapper for the Brotli codebase git clone https://github.com/bagder/libbrotli && cd libbrotli sudo ./autogen.sh sudo .configure sudo make sudo make install cd /opt # we’ll set up Nginx module git clone https://github.com/google/ngx_brotli sudo apt-get build-dep nginx cd /opt mkdir nginx && cd nginx sudo apt-get source nginx # above will create a nginx-1.x.x dir with the source code cd nginx-1.x.x nano debían/rules # add the line # --add-module=/opt/ngx_brotli \ # sudo dpkg-buildpackage -b cd .. sudo dpkg -i nginx_*_all.deb nginx-full_*_amd64.deb # In case of error, you may need to run apt-get remove nginx-core and then run the above command |
Example configuration on nginx config file ( /etc/nginx/nginx.conf
) is like gzip :
1 2 3 4 5 6 |
brotli on; brotli_static on; brotli_min_length 1000; brotli_buffers 32 8k; brotli_comp_level 5; brotli_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/ecmascript application/json image/svg+xml; |
Run configtest and restart Nginx.
Here’s what we’ve got for you which might like :
Additionally, performing a search on this website can help you. Also, we have YouTube Videos.
Take The Conversation Further ...
We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!
If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.
Contact Us