Brotli for NGINX

Brotli is defined in RFC 7932 and reading the RFC is fun, it is most simply described by

Brotli is an open-source algorithm from Google used for compression It is an alternative to the famous GZIP compression. Several case studies have shown that Brotli excels in compression speed and file size in comparison to GZIP when using the default. Also, all modern browsers support Brotli by now, though only over HTTPS.

An implementation of Brotli is available for NGINX by Google. As it needs to be compiled from source I have attached my code below to build it for Debian/Ubuntu.

Warning: Before any implementing HTTP compression, be aware that you may be exposing yourself to BREACH-attacks!

# Get google/ngx_brotli source code
cd /usr/local/src
git clone git://
# get the google/ngx_brotli submodules
cd ngx_brotli
git submodule update --init
# Get the currently installed Nginx source code (Debian package)
cd /usr/local/src/
apt source nginx
NGINX_SOURCE=$(ls -td -- */ | head -n 1 | cut -d'/' -f1)
# Find the ./configure line Nginx was compiled with
nginx -V
# Call `./configure` with the arguments from "configure arguments:" output above, **except** for the `--add-dynamic-module` ones, and append `--add-dynamic-module=../ngx_brotli` to the end
./configure --with-cc-opt='-g -O2 ....................... --add-dynamic-module=../ngx_brotli
# Build and copy build modules to the right place
make modules
mkdir -p /usr/local/lib/nginx/modules/
cp objs/ /usr/local/lib/nginx/modules/
cp objs/ /usr/local/lib/nginx/modules/
# cleanup
rm -rf /usr/local/src/$NGINX_SOURCE
rm -rf /usr/local/src/ngx_brotli

Enable by adding following to enforce Brotli compression in NGINX :

Enable brotli module
Configure Directives
Enable brotli module
load_module /usr/local/lib/nginx/modules/;
load_module /usr/local/lib/nginx/modules/;
Configure Directives
http {
server {
brotli on;
brotli_min_length 1100;
brotli_buffers 4 32k;
brotli_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/ image/svg+xml;
brotli_comp_level 6;