Skip to content

How to Enable Brotli Compression in Nginx

Updated 2 min read

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 file style.css.br exists next to style.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.

Related services

Managed CWP VPS

CentOS Web Panel pre-installed and looked after by our engineers.

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Was this answer helpful?

Still stuck? Open a ticket