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
-
Remove google/ngx_brotli’s packages (
nginx-module-brotli, or the distribution’s own, such as Debian’slibnginx-mod-http-brotli-filterandlibnginx-mod-http-brotli-static) or its twoload_modulelines. Its two.sofiles become one. -
Install or build ngx_mbrotli and load it:
load_module modules/ngx_mbrotli.so; -
Run
nginx -tand 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_bufferstakes effect. google/ngx_brotli accepts the directive but ignores it; here it works the same way asgzip_buffers.- Encoders are reused by default
(
brotli_reuse_memory), each keeping all of its working memory between responses (brotli_retention_policy). Setbrotli_reuse_memory offto allocate per response as google/ngx_brotli does. Peak memory still follows the number of responses being compressed at once, times the working set thatbrotli_comp_levelandbrotli_windowneed. 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-ttfand 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
| Directive | Context | Default |
|---|---|---|
brotli_reuse_memory | http, server, location | on |
brotli_retention_policy | http, server, location | aggressive |
brotli_idle_encoders | http | 4 |
brotli_thread_pool | http, server, location | off |
brotli_parallel_segment_size | http, server, location | 1m |
brotli_parallel_tasks | http, server, location | 4 |
brotli_parallel_compressors | http | 4 |
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.