Brotli compresses supported web responses before they are sent to a browser, which can reduce transferred data. This guide explains how to enable it on an independently managed NGINX installation with a compatible Brotli module.
Before you start
You need administrator access and a backup of the active NGINX configuration. Compression uses server resources, and the benefit depends on the content and settings.
For NGINX managed by cPanel, Plesk or another hosting panel, use that product’s supported module and configuration process. Direct edits or replacement binaries may be overwritten or break its integration.
Check module support
Inspect the installed NGINX build:
nginx -VA static build may list Brotli in its build options. This output alone does not prove whether a dynamic Brotli module is installed or loaded. Check the active configuration’s load_module directives and the module package documentation.
Install a compatible module
Use a module built for the exact NGINX package and binary interface you run. Do not replace the working server with a generic source build just to add compression.
For example, Ubuntu 24.04’s distribution repository provides libnginx-mod-http-brotli-filter for its matching NGINX package. On that installation, check the available packages and proposed changes before installing:
apt-cache policy nginx libnginx-mod-http-brotli-filter
sudo apt install libnginx-mod-http-brotli-filterDo not combine this distribution module with an incompatible third-party NGINX package. Other distributions and package sources may use different packages or require a separately built module.
Follow the package’s module-loading instructions. A manually loaded dynamic filter module uses a directive such as the following in the main configuration context, above http, with the actual installed path:
load_module modules/ngx_http_brotli_filter_module.so;Do not add a duplicate directive if the package already enables the module through an included configuration file.
Enable Brotli compression
Add the following in the appropriate http, server or location context after checking existing compression settings:
brotli on;
brotli_comp_level 6;
brotli_types text/plain text/css application/javascript application/json image/svg+xml application/xml;HTML responses are included by default by this module. Avoid recompressing formats already compressed, such as JPEG images. Keep an appropriate gzip fallback if your existing configuration requires it for clients that do not advertise Brotli support.
Test and reload
Validate the configuration first:
sudo nginx -tResolve any unknown directive, module compatibility or syntax errors before proceeding. On a systemd installation using nginx.service, reload only after validation succeeds:
sudo systemctl reload nginxVerify compression
Use a GET request for a suitable text response, replacing the example URL:
curl -sS -D - -o /dev/null -H 'Accept-Encoding: br' https://example.com/styles.cssCheck for Content-Encoding: br. Small responses, cached responses or other content types may not be compressed. A CDN may set its own compression behaviour, so verify the intended server layer as well as the public response.
Test a client without Brotli support and monitor CPU usage, errors and response behaviour after the change.