Brotli

Learn how to use the Brotli module with NGINX Plus

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 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 install epel-release -y
    

Installation

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

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

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

    dnf install nginx-plus-module-brotli
    
  • for Debian and Ubuntu:

    apt-get install nginx-plus-module-brotli
    
  • for SLES 15:

    zypper install nginx-plus-module-brotli
    
  • for FreeBSD:

    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 configuration and reload NGINX Plus to enable the module:

    nginx -t && nginx -s reload
    

More Info