Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Migrating from google/ngx_brotli

ngx_mbrotli provides the same two modules, directives, defaults and variable as google/ngx_brotli, so an existing configuration keeps working unchanged.

Steps

  1. Remove google/ngx_brotli’s packages (nginx-module-brotli, or the distribution’s own, such as Debian’s libnginx-mod-http-brotli-filter and libnginx-mod-http-brotli-static) or its two load_module lines. Its two .so files become one.

  2. Install or build ngx_mbrotli and load it:

    load_module modules/ngx_mbrotli.so;
    
  3. Run nginx -t and reload. The rest of the configuration stays as it is.

There is no Brotli C library or deps/brotli submodule to build any more.

What behaves differently

  • brotli_buffers takes effect. google/ngx_brotli accepts the directive but ignores it; here it works the same way as gzip_buffers.
  • Encoders are reused by default (brotli_reuse_memory), each keeping all of its working memory between responses (brotli_retention_policy). Set brotli_reuse_memory off to allocate per response as google/ngx_brotli does. Peak memory still follows the number of responses being compressed at once, times the working set that brotli_comp_level and brotli_window need. See Memory and encoder reuse.
  • Responses can be compressed on a thread pool (brotli_thread_pool), in segments that are compressed in parallel. See Compressing on a thread pool.
  • The size hint comes from Content-Length. When the length is known it is passed to the encoder, which uses it to choose a match finder at levels 4–9.
  • Fonts are compressed in Brotli’s font mode. Responses whose type is an uncompressed TrueType or OpenType font (font/ttf, font/otf, font/sfnt, font/collection, application/vnd.ms-fontobject, application/x-font-ttf and similar) use font mode, which makes them about 0.1–0.3% smaller at levels 4–11 and does not affect speed. All other responses, including WOFF and WOFF2 fonts, which are already compressed, use generic mode as google/ngx_brotli does. Text mode is not used: it does not change Brotli’s output.
  • The pure-Rust mbrotli encoder replaces the C library. It produces the same bytes as Google’s encoder at every level, so you do not need to vendor or build the C Brotli library.

New directives

DirectiveContextDefault
brotli_reuse_memoryhttp, server, locationon
brotli_retention_policyhttp, server, locationaggressive
brotli_idle_encodershttp4
brotli_thread_poolhttp, server, locationoff
brotli_parallel_segment_sizehttp, server, location1m
brotli_parallel_taskshttp, server, location4
brotli_parallel_compressorshttp4

Reporting a difference

If the module behaves differently from google/ngx_brotli with the same configuration, and the difference is not listed above, open an issue with the Differs from google/ngx_brotli template.