Updated: 29 September 2026 · Applies to: Nginx 1.20 and later with the ngx_brotli modules on AlmaLinux and Rocky Linux 9 and 10 (EPEL), Ubuntu 24.04 and 26.04, Debian 13
Brotli is a compression method that makes text files (HTML, CSS, JavaScript, JSON, SVG) smaller than gzip does, so pages load faster. All current browsers support it, over HTTPS. Nginx gets Brotli support from the ngx_brotli modules, which most distributions package. Do not download prebuilt module files from other websites, as older guides suggest: a module must be built for exactly your Nginx version. We tested the setup on Debian 13 and AlmaLinux 10: CSS files were sent with Content-Encoding: br to clients that asked for it.
1. Install the modules
apt install libnginx-mod-http-brotli-filter libnginx-mod-http-brotli-static # Ubuntu, Debian dnf install epel-release && dnf install nginx-mod-brotli # AlmaLinux, Rocky Linux
The packages load the modules automatically. On AlmaLinux and Rocky Linux 9, EPEL's module is built for the default Nginx 1.20; if you switched to another Nginx version (module stream or nginx.org packages), it will not match.
2. Enable Brotli
Create /etc/nginx/conf.d/brotli.conf:
brotli on; brotli_comp_level 5; brotli_static on; brotli_types text/plain text/css application/javascript application/json image/svg+xml application/xml;
brotli on: compress responses on the fly. HTML is always included.brotli_comp_level: 0 to 11. Levels around 4 to 6 give most of the gain for little CPU; the highest levels are for files you compress in advance.brotli_static on: if a filestyle.css.brexists next tostyle.css, send it directly instead of compressing each time.
Keep gzip enabled as well, for clients that do not support Brotli.
3. Test and reload
nginx -t && systemctl reload nginx curl -s -o /dev/null -D - -H "Accept-Encoding: br" https://example.com/style.css | grep -i content-encoding
The response should include content-encoding: br. Browsers send Accept-Encoding: br only over HTTPS.
Behind a CDN or on a control panel
If your site is behind a CDN such as Cloudflare, the CDN usually compresses for visitors itself. On control panels that manage Nginx (for example cPanel's NGINX reverse proxy or CWP), use the panel's own options instead of editing Nginx by hand.
Official documentation: ngx_brotli module.