Brotli is defined in RFC 7932 and reading the RFC is fun, it is most simply described by brotli.pro:
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!
WORKDIR="~/ng_workdir"mkdir $WORKDIR# Get google/ngx_brotli source code + google/ngx_brotli submodulescd $WORKDIRgitclonegit://github.com/google/ngx_brotli.gitcdngx_brotligitsubmoduleupdate--init# Get the currently installed Nginx source code (Debian package)cd $WORKDIRaptsourcenginxNGINX_SOURCE=$(ls-td--*/|head-n1|cut-d'/'-f1)cd $NGINX_SOURCE# Find the ./configure line Nginx was compiled withnginx-V# *** REQUIRES HUMAN INTERACTION ***# Call `./configure` with ALL 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 placemake modulesmkdir -p /usr/local/lib/nginx/modules/sudo cp objs/ngx_http_brotli_filter_module.so /usr/local/lib/nginx/modules/sudo cp objs/ngx_http_brotli_static_module.so /usr/local/lib/nginx/modules/# cleanuprm -rf $WORKDIR
Enable by adding following to enforce Brotli compression in NGINX :