Skip to content

How to Enable Brotli in nginx

Key idea:

Brotli (brotli.org, Google) is a compression algorithm 15-25% better than gzip for text (HTML/CSS/JS). Client support 95%+ by 2026. Install in nginx: compile ngx_brotli module (not in the default dynamic pool) or use the nginx-extras package. Add 3 directives + server reload.

Below: step-by-step, working examples, common pitfalls, FAQ.

Check your site's speed →

Step-by-Step Setup

  1. Install ngx_brotli via pre-built package: apt install nginx-module-brotli (Ubuntu 22.04+)
  2. Or compile: git clone --recursive https://github.com/google/ngx_brotli + configure nginx with --add-module
  3. In nginx.conf (http context): load_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so;
  4. In server block: brotli on; brotli_comp_level 6; brotli_types text/plain text/css application/json application/javascript;
  5. Static files (pre-compressed .br): brotli_static on;
  6. nginx -t && systemctl reload nginx
  7. Verify: curl -H "Accept-Encoding: br" -I https://example.com | grep -i "content-encoding" — should be "br"

Working Examples

ScenarioConfig
nginx.conf modulesload_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so;
server blockbrotli on; brotli_comp_level 6; brotli_static on; brotli_types text/plain text/css application/json application/javascript application/xml+rss text/xml image/svg+xml;
Pre-compress filesfind /var/www -type f \( -name "*.css" -o -name "*.js" \) | xargs -I{} brotli -q 11 "{}"
ApacheLoadModule brotli_module modules/mod_brotli.so\nBrotliCompressionQuality 5

Common Pitfalls

  • brotli_types missing required MIME — nothing compressed
  • compression level 11 (max) in line — CPU 100%. For realtime 4-6 is optimal
  • brotli_static on without pre-compressed files — no change
  • No gzip fallback — old clients (<5%) without Brotli get uncompressed
  • Proxy-cached responses with gzip — Brotli won't apply to already-gzipped

TL;DR

To enable Brotli compression in Nginx, you need to install the Brotli module, configure it in your Nginx configuration file, and set the appropriate directives. Use the command sudo apt install nginx-module-brotli to install the module, then add brotli on; and brotli_types text/html text/css application/javascript; in the relevant server block to activate Brotli compression for specified file types.

Step-by-Step Guide to Enable Brotli Compression in Nginx

Enabling Brotli compression in Nginx is a straightforward process that can significantly enhance the performance of your web applications by reducing the size of transmitted data. Follow these steps to activate Brotli compression on your Nginx server.

1. Prerequisites

Before proceeding, ensure you have the following:

  • A server running Nginx version 1.9.11 or later.
  • Access to the server with sufficient privileges to install modules.
  • A basic understanding of Nginx configuration files.

2. Install Brotli Module

To use Brotli compression, you need to install the Brotli module for Nginx. Depending on your operating system, the installation process may vary.

For Ubuntu/Debian
sudo apt update
sudo apt install nginx-module-brotli
For CentOS/RHEL

Use the following commands to install the Brotli module:

sudo yum install epel-release
sudo yum install nginx-mod-http-brotli

3. Configure Nginx for Brotli Compression

Once the Brotli module is installed, you need to configure Nginx to enable Brotli compression. Open your Nginx configuration file, usually located at /etc/nginx/nginx.conf or within the /etc/nginx/conf.d/ directory.

sudo nano /etc/nginx/nginx.conf

Within the http block, add the following configuration:

brotli on;
brotli_static on;
brotli_types text/html text/css application/javascript application/json image/svg+xml;

This configuration enables Brotli compression and specifies the MIME types that should be compressed. Adjust the MIME types according to your application needs.

4. Additional Configuration Options

You can further customize Brotli settings with options like brotli_comp_level and brotli_vary. The brotli_comp_level directive controls the compression level, where a value of 1 is the fastest and 11 is the most compressed:

brotli_comp_level 6;

The default value is 6, which provides a good balance between compression ratio and CPU usage. The brotli_vary directive enables the Vary header for browsers that support Brotli, which helps in caching:

brotli_vary on;

5. Test Your Configuration

After making changes, test your Nginx configuration for syntax errors:

sudo nginx -t

If there are no errors, reload Nginx to apply the changes:

sudo systemctl reload nginx

6. Verify Brotli Compression

To confirm that Brotli compression is working, you can use tools such as GiftOfSpeed or Check Gzip Compression. These tools will show you whether Brotli is enabled and provide details on the compression ratio.

Conclusion

Enabling Brotli compression in Nginx can significantly improve the loading times of your web applications, enhancing user experience and potentially boosting SEO rankings. By following the steps outlined above, you can easily set up Brotli compression and optimize your server's performance.

PerformanceOverall speed score 0-100
Core Web VitalsLCP, FID, CLS — Google metrics
Page SizeSize of HTML, CSS, JS, images
RecommendationsSpecific tips for improvement

Why teams trust us

Lighthouse
analysis engine
CWV
Core Web Vitals
4
Lighthouse categories
Precise
recommendations

How it works

1

Enter page URL

2

Lighthouse analyzes

3

Get CWV scores & tips

Why Does Site Speed Matter?

Page load speed directly impacts conversion, SEO rankings, and user satisfaction. Google uses Core Web Vitals as a ranking factor. Every extra second of load time cancost up to 7% in conversions.

Lighthouse Analysis

Google Lighthouse-based analysis: Performance, Accessibility, Best Practices, SEO.

Core Web Vitals

LCP (rendering), FID (interactivity), CLS (visual stability) — key Google metrics.

Resource Analysis

Breakdown by type: HTML, CSS, JavaScript, images, fonts. Size, request count, blocking resources.

Actionable Advice

Specific recommendations with savings estimates: image compression, caching, minification, etc.

Mobile vs Desktop

Mobile
  • Tested on Moto G Power emulation (slow CPU)
  • Network: 4G (1.6 Mbps, 150ms RTT)
  • Stricter speed scoring
  • Google indexes mobile-first
  • Priority for SEO optimization
Desktop
  • High CPU performance
  • Fast connection without throttling
  • Scores typically 20-40 points higher
  • Important for B2B and corporate sites
  • Use for baseline comparisons

Who uses this

SEO

Core Web Vitals for rankings

Developers

performance optimization

Marketers

speed = conversions

DevOps

performance regression

Common Mistakes

Unoptimized imagesImages can be up to 70% of page weight. Use WebP/AVIF and lazy loading.
Render-blocking JS in &lt;head&gt;Scripts without async/defer block rendering. Move to end or add attribute.
No static asset cachingWithout Cache-Control, the browser reloads CSS/JS on every visit.
Too many HTTP requestsEach request adds latency. Bundle files, use sprites, or inline critical CSS.
Missing compression (gzip/brotli)Compression reduces text resource size by 60-80%. Enable brotli on the server.

Best Practices

Optimize imagesWebP for photos, SVG for icons. loading="lazy" for images below the fold.
Enable brotli compressionBrotli is 15-20% more efficient than gzip. Configure in nginx: brotli on;
Set up cachingStatic: Cache-Control: max-age=31536000, immutable. HTML: max-age=0, s-maxage=60.
Preload critical resources<link rel="preload"> for fonts and CSS. Reduces LCP by 200-500ms.
Test regularlySpeed degrades over time. Check after each deploy and monthly.

Get more with a free account

Speed check history, competitor comparison and PageSpeed monitoring.

Sign up free

Learn more

Frequently Asked Questions

How much better is Brotli than gzip?

For text (HTML/CSS/JS): 15-25% smaller at the same CPU. For binaries (already compressed) — minimal.

Does Brotli work over HTTPS?

Yes; clients don't send Accept-Encoding: br over plain HTTP. Modern sites are all HTTPS.

Client compatibility?

Chrome 50+, Firefox 44+, Safari 11+ (2017). IE no support. By 2026 coverage is 95%+.

How do I verify it works?

<a href="/en/speed">Enterno Speed checker</a> shows response headers. Or DevTools → Network → Response Headers → Content-Encoding.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.