Brotli Compression
Your gzip was fine. Brotli is better.
- Package
- nginx-module-brotli
- Section
- Compression
- Replaces
- libnginx-mod-http-brotli-filter
- Upstream
- github.com/google/ngx_brotli ↗
- Distros
- Debian 12, 13 · Ubuntu 22.04, 24.04, 26.04
- Arch
- amd64, arm64
What it does
Brotli is Google's compression algorithm. It squeezes text content 15-25% smaller than gzip at comparable speeds, and every major browser has supported it for years. nginx doesn't ship it. This module fixes that. Compression happens on the fly based on the Accept-Encoding header. If you'd rather pre-compress assets at build time and skip the per-request CPU work, pair it with nginx-module-brotli-static.
When to use it
- Reduce bandwidth usage and page load times for HTML, CSS, and JS assets
- Improve Core Web Vitals by shrinking the transfer size of text assets
- Replace or supplement gzip compression without touching application code
- Serve smaller API responses to JavaScript clients
Configuration
A starting point. Adjust to taste.
# Inside your http {} block:
brotli on;
brotli_comp_level 6;
brotli_types
text/html
text/css
text/plain
application/javascript
application/json
application/xml
image/svg+xml;Install from scratch
You'll need nginx from nginx.org configured first. These packages won't load on the distro nginx. Then add the Blendbyte repository if you haven't already:
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://apt.blendbyte.net/nginx/blendbyte-archive-keyring.gpg \
| sudo tee /etc/apt/keyrings/blendbyte.gpg >/dev/null
echo "deb [signed-by=/etc/apt/keyrings/blendbyte.gpg] https://apt.blendbyte.net/nginx $(lsb_release -cs) main" \
| sudo tee /etc/apt/sources.list.d/blendbyte.list
sudo apt update
sudo apt install nginx-module-brotliMost modules auto-enable on install. If yours didn't:
$ sudo ln -s /etc/nginx/modules-available/50-mod-brotli.conf \
/etc/nginx/modules-enabled/
$ sudo nginx -t && sudo systemctl reload nginxReplacing a Sury package?
This replaces libnginx-mod-http-brotli-filter from the old Sury nginx repository. The package declares Replaces and Conflicts, so once your apt sources point at nginx.org and Blendbyte, a regular apt upgrade swaps it in. No manual cleanup.
Switching sources also moves you from Sury's nginx binary to nginx.org's. The migration guide walks through it in one go.
Upstream project
We package this from the upstream open-source project. If it's a bug in the module itself (not in our packaging), report it upstream at github.com/google/ngx_brotli ↗