Building from source
Build the module yourself when no package matches your nginx: a custom build, freenginx, Angie, or an nginx.org version older than the packaged ones.
Requirements
- Rust 1.89 or newer;
- libclang (used by
nginx-systo generate bindings); - the NGINX source tree, configured with the same arguments as the NGINX binary
that will load the module, plus
--with-compat. Runnginx -Vto see those arguments. Only./configureis required, notmake. A freenginx or Angie source tree works the same way (for Angie, take the arguments fromangie -V).
The Brotli C library is not needed.
Build
cd nginx-1.30.8
./configure --with-compat <arguments from nginx -V>
cd /path/to/ngx_mbrotli
NGINX_BUILD_DIR=/path/to/nginx-1.30.8/objs cargo build --release
The module is written to target/release/libngx_mbrotli.so
(libngx_mbrotli.dylib on macOS). Load it at the top level of nginx.conf:
load_module /path/to/libngx_mbrotli.so;
brotli_thread_pool and
brotli_parallel_compressors are
compiled in only when the NGINX tree was configured with --with-threads.
NGINX forks
freenginx and Angie are
supported and tested in CI (freenginx 1.31, Angie 1.12) alongside NGINX 1.28,
1.30 and 1.31. Point NGINX_BUILD_DIR at the fork’s configured tree; nothing
else changes.
freenginx:
curl -sSfL https://freenginx.org/download/freenginx-1.31.6.tar.gz | tar xz
cd freenginx-1.31.6
./configure --with-compat <arguments from nginx -V>
cd /path/to/ngx_mbrotli
NGINX_BUILD_DIR=/path/to/freenginx-1.31.6/objs cargo build --release
Angie, which names its binary angie:
curl -sSfL https://download.angie.software/files/angie-1.12.6.tar.gz | tar xz
cd angie-1.12.6
./configure --with-compat <arguments from angie -V>
cd /path/to/ngx_mbrotli
NGINX_BUILD_DIR=/path/to/angie-1.12.6/objs cargo build --release
Then add load_module /path/to/libngx_mbrotli.so; to the fork’s main
configuration file (/etc/angie/angie.conf for Angie) and check it with
nginx -t or angie -t.
Vendored NGINX
To build against a vendored NGINX instead, enable the vendored feature (see
nginx-src). Prefer building against the exact
sources and configuration that run in production: NGINX refuses to load a
module that is not binary compatible with it.
Next
Configure the module, then check it with
nginx -t and a request:
curl -s -o /dev/null -D - -H 'Accept-Encoding: br' http://localhost/ | grep -i content-encoding