Brotli

Overview

Brotli is a general‑purpose, lossless data compression algorithm that uses a variant of the LZ77 algorithm, Huffman coding, and second‑order context modeling. Its compression ratio is comparable to the best currently available general‑purpose compression methods. Its speed is similar to DEFLATE but with denser compression.

The ngx_brotli module enables Brotli compression in F5 NGINX Plus and consists of two modules:

  • ngx_brotli filter module – for compressing responses on-the-fly
  • ngx_brotli static module - for serving pre-compressed files

Prerequisites

  1. Check the Technical Specifications page to verify that the module is supported by your operating system.

  2. If required, install the epel-release dependency

    • for Amazon Linux 2 LTS:
    sudo amazon-linux-extras install epel -y
    • for CentOS, Oracle Linux, and RHEL:
    sudo yum update && \
    sudo yum install epel-release -y

Installation

Install the Brotli module package nginx-plus-module-brotli.

  • for Amazon Linux 2 LTS, CentOS, Oracle Linux, and RHEL:

    sudo yum update && \
    sudo yum install nginx-plus-module-brotli
  • for Amazon Linux 2023, AlmaLinux, Rocky Linux:

    sudo dnf update && \
    sudo dnf install nginx-plus-module-brotli
  • for Debian and Ubuntu:

    sudo apt update && \
    sudo apt install nginx-plus-module-brotli
  • for SLES 15:

    sudo zypper refresh && \
    sudo zypper install nginx-plus-module-brotli
  • for FreeBSD:

    sudo pkg update && \
    sudo pkg install nginx-plus-module-brotli

Configuration

After installation you will need to enable and configure Brotli modules in NGINX Plus configuration file nginx.conf.

  1. Enable dynamic loading of Brotli modules with the load_module directives specified in the top-level (“main”) context:

    load_module modules/ngx_http_brotli_filter_module.so; # for compressing responses on-the-fly
    load_module modules/ngx_http_brotli_static_module.so; # for serving pre-compressed files
    
    http {
        #...
    }
  2. Enable Brotli compression and perform additional configuration as required by the ngx_brotli module. Brotli compression can be configured on the http, server or location levels:

    http {
    
        server {
            brotli on;
            #...
        }
    }
  3. Test the NGINX Plus configuration. In a terminal, type-in the command:

    nginx -t

    Expected output of the command:

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf is successful
  4. Reload the NGINX Plus configuration to enable the module:

    nginx -s reload

More Info