Joseph Matino
  • Servers
    • Proxmox
  • Web Dev
  • Gaming
    • PC Gaming
  • Guides
  • Security
Font ResizerAa
Joseph MatinoJoseph Matino
Font ResizerAa
Search
  • Servers
    • Proxmox
  • Web Dev
  • Gaming
    • PC Gaming
  • Guides
  • Security
Complete Fc-San Setup Guide For Proxmox Ve 9.0. Configure Shared Storage, Enable Snapshots, Multipath Setup, And Clustering Step By Step

How To Set Up FC-SAN With Proxmox VE 9.0 Snapshots

Joseph Matino
Joseph Matino
2 weeks ago
FacebookLike
InstagramFollow
YoutubeSubscribe
TiktokFollow
Follow US
  • Terms & Conditions
  • Privacy Policy
  • Contact
© Joseph Matino. All Rights Reserved.

Home – Blog – Servers

How to Install and Enable Brotli Compression on Nginx Ubuntu

Joseph Matino
Last updated: August 12, 2025 2:53 pm
ByJoseph Matino
Step-By-Step Guide To Install Brotli Nginx Compression On Ubuntu 22.04. Includes Compilation, Hestiacp Configuration, And Troubleshooting Tips.

Running websites means you start thinking about compression more than you want to. Most people just use whatever gzip compression their server came with because it works and requires no setup. Brotli compression can make files 20-26% smaller without using extra server power, which translates into noticeably faster page loads for visitors. The difference becomes especially apparent on sites with heavy CSS frameworks, large JavaScript libraries, or content management systems like WordPress.

Nginx does not ship with Brotli compression modules included in the standard installation packages. Getting it to work requires compiling the modules from source code and configuring them properly for your specific server environment. The process sounds intimidating if you have never compiled nginx modules before, but it follows a straightforward sequence of steps. Once completed, the performance benefits last permanently without requiring ongoing maintenance or updates.

Article Content
Brotli vs Gzip: Which Compression is BetterWhat You Need Before StartingStep 1: Check Your Current Nginx SetupStep 2: Install Development ToolsStep 3: Download and Compile the ModuleStep 4: Copy the Compiled ModulesStep 5: Configure Main Nginx SettingsStep 6: Configure HestiaCP Site SettingsFinal Step: Test Your Brotli SetupCDN Setup for Better PerformanceFix Common ProblemsOther Web Server OptionsMonitor Your Performance Gains

This walkthrough covers Brotli installation on Ubuntu 22.04 servers including the specific steps needed for HestiaCP environments which handle configuration differently than standard nginx setups. The compilation and setup process takes about 30 minutes of active work, though some steps involve waiting for downloads and builds to complete.

Most of the time is spent on preparation and verification rather than complex technical work. By the end you will know how to compile the modules, set up the configuration files, test that compression works, and troubleshoot any problems that come up during installation.

Brotli vs Gzip: Which Compression is Better

Most web servers still use gzip compression because it has been the standard for years. However, Brotli offers measurably better compression ratios without requiring more server resources, making it ideal for modern websites that prioritize performance.

The difference becomes especially noticeable on sites with heavy CSS frameworks, JavaScript libraries, and custom stylesheets. When managing multiple client sites, I noticed that pages with larger asset files benefited the most from Brotli compression. The algorithm excels at compressing text-based content, which includes most web assets except images.

Real Performance Improvements You Can Expect:

The compression improvements translate directly to faster page loads, better Core Web Vitals scores, and improved user experience across all devices. From testing on production sites, CSS files typically compress 20-30% smaller than gzip, while JavaScript bundles see similar size reductions. HTML content benefits from better compression ratios, and server CPU usage remains the same as gzip.

The most noticeable improvement comes with network bandwidth usage, which decreases significantly for users on slower connections or mobile networks. This reduction in data transfer also helps reduce hosting costs for sites with high traffic volumes.

File TypeOriginal SizeGzip CompressedBrotli Compressed
WordPress Main CSS (theme + plugins)1.2 MB180 KB (85% reduction)142 KB (88% reduction)
JavaScript Bundle (jQuery + plugins)950 KB285 KB (70% reduction)225 KB (76% reduction)
Bootstrap CSS Framework158 KB28 KB (82% reduction)22 KB (86% reduction)
HTML Blog Post (with images)125 KB32 KB (74% reduction)25 KB (80% reduction)
JSON API Response (WordPress REST)89 KB24 KB (73% reduction)18 KB (80% reduction)
Font Awesome CSS + Icons76 KB18 KB (76% reduction)14 KB (82% reduction)
Custom JavaScript (vanilla + libraries)245 KB68 KB (72% reduction)52 KB (79% reduction)
WordPress Admin CSS340 KB58 KB (83% reduction)46 KB (86% reduction)
SVG Icons Sprite45 KB12 KB (73% reduction)9 KB (80% reduction)
Web Font Files (WOFF2)85 KB84 KB (1% reduction)82 KB (4% reduction)

Browser support for Brotli covers over 96% of internet users, with automatic fallback to gzip for older browsers. This means you get improved performance for the vast majority of visitors while maintaining compatibility for everyone else.

Google’s original research demonstrates that Brotli delivers 20-26% better compression compared to gzip across various file types. The algorithm was initially developed for web font compression but quickly expanded to handle all text-based web content.

What You Need Before Starting

Running this installation on Ubuntu 22.04 with HestiaCP requires some preparation. Your server needs enough resources to compile nginx modules, which means at least 2GB of RAM and some temporary storage space.

Make sure you have root access or sudo privileges on your server. The compilation process downloads source code and builds binary files, so your user account needs permission to install packages and modify nginx configuration files.

During my first installation attempt, I ran into issues with missing development packages. Ubuntu servers often ship with minimal software installed, so you might need to install compilation tools even on seemingly complete systems. The error messages usually indicate which packages are missing, but installing everything upfront saves time troubleshooting later.

Independent verification from multiple sources confirms that JavaScript files are roughly 15% smaller, HTML files around 20% smaller, and CSS files approximately 16% smaller when using Brotli compression compared to gzip.

You will also need to know your exact nginx version since the Brotli module must match perfectly. Most HestiaCP installations use nginx from the official repositories, but custom installations might use different versions.

Step 1: Check Your Current Nginx Setup

Start by checking which nginx version your server runs. This information determines which source code to download for compilation.

nginx -v

Expected Output:

nginx version: nginx/1.29.0

Write down this version number. Next, check where nginx expects to find modules:

nginx -V 2>&1 | grep modules-path

Expected Output:

--modules-path=/usr/lib/nginx/modules

This tells us where to install the compiled modules.

Step 2: Install Development Tools

Update your package list first:

sudo apt update

Install the tools needed for compilation:

sudo apt install build-essential git gcc cmake libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev

These packages provide everything needed to compile nginx modules. The installation takes a few minutes and requires about 500MB of storage.

Step 3: Download and Compile the Module

Move to a temporary directory for the compilation work:

cd /tmp

Download the nginx source code. Important: Replace 1.29.0 with your exact nginx version from the first step.

wget https://nginx.org/download/nginx-1.29.0.tar.gz
tar -xzf nginx-1.29.0.tar.gz

Download the Brotli module source:

git clone --recursive https://github.com/google/ngx_brotli.git

Now compile the modules. Enter the nginx source directory:

cd nginx-1.29.0

Configure the build to create dynamic modules:

./configure --with-compat --add-dynamic-module=../ngx_brotli

Compile the modules:

make modules

Expected Output:

cc -c -fPIC -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -Wno-deprecated-declarations -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I ../ngx_brotli/deps/brotli/c/include -I objs -I src/http -I src/http/modules \
        -o objs/addon/filter/ngx_http_brotli_filter_module.o \
        ../ngx_brotli/filter/ngx_http_brotli_filter_module.c
cc -o objs/ngx_http_brotli_filter_module.so \
objs/addon/filter/ngx_http_brotli_filter_module.o \
objs/ngx_http_brotli_filter_module_modules.o \
-L../ngx_brotli/deps/brotli/c/../out -lbrotlienc -lbrotlicommon -lm \
-shared

The compilation process takes 5-10 minutes depending on your server specifications. If the compilation fails with errors about missing libraries, you might need to install additional development packages.

Common Error and Solution: If you see git submodule update --init errors, navigate to the ngx_brotli directory and run:

cd ../ngx_brotli
git submodule update --init
cd ../nginx-1.29.0

Step 4: Copy the Compiled Modules

Create the modules directory if it does not exist:

sudo mkdir -p /usr/lib/nginx/modules

Copy the compiled modules to the correct location:

ls -la /usr/lib/nginx/modules/

You should see both Brotli module files listed.

Step 5: Configure Main Nginx Settings

Edit the main nginx configuration file:

sudo nano /etc/nginx/nginx.conf

Add these lines at the very top of the file, before any other directives:

# Brotli modules
load_module /usr/lib/nginx/modules/ngx_http_brotli_filter_module.so;
load_module /usr/lib/nginx/modules/ngx_http_brotli_static_module.so;

In the http block, find your existing gzip configuration and replace it completely with Brotli:

# Brotli compression (replaces gzip)
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_min_length 1024;
brotli_types
    text/plain
    text/css
    text/xml
    text/javascript
    application/javascript
    application/xml+rss
    application/json
    image/svg+xml
    font/ttf
    font/otf
    font/woff
    font/woff2;

add_header Vary Accept-Encoding;

Test the configuration:

sudo nginx -t
sudo systemctl reload nginx

Step 6: Configure HestiaCP Site Settings

For HestiaCP users, the Brotli compression settings go in your site-specific configuration, not the main nginx.conf file. Navigate to your domain’s configuration directory:

cd /home/username/conf/web/yourdomain.com/

Edit the custom nginx configuration file:

sudo nano nginx.conf_custom

Add the complete Brotli configuration to this file:

# Enable brotli compression for this site
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_min_length 1024;
brotli_types
    text/plain
    text/css
    text/xml
    text/javascript
    application/javascript
    application/xml+rss
    application/json
    image/svg+xml
    image/avif
    font/ttf
    font/otf
    font/woff
    font/woff2;

add_header Vary Accept-Encoding;

This is the correct approach: Main nginx.conf loads modules, site config enables compression. Test and reload:

sudo nginx -t
sudo systemctl reload nginx

Final Step: Test Your Brotli Setup

Test your main site:

curl -H "Accept-Encoding: br" -I https://yourdomain.com/

Expected Output:

HTTP/2 200
server: nginx
date: Tue, 12 Aug 2025 09:18:21 GMT
content-type: text/html; charset=UTF-8
content-encoding: br

The key line is content-encoding: br which confirms Brotli is working.

Test a CSS file to verify static assets are compressed:

curl -H "Accept-Encoding: br" -I https://yourdomain.com/wp-content/themes/yourtheme/style.css

Expected Output:

HTTP/2 200
server: nginx
content-type: text/css
expires: Thu, 11 Sep 2025 09:18:56 GMT
content-encoding: br

CDN Setup for Better Performance

Once Brotli compression works on your nginx server, configure your CDN service to take advantage of the improved compression. The approach depends on which CDN provider you use and how their compression features work.

For CDN services like GCORE that support fetch compressed features, configure them to pull compressed content from your server rather than compressing files themselves. This approach leverages your server’s Brotli compression while using the CDN’s global distribution network. In my setup with GCORE, I disabled their compression options and enabled “Fetch Compressed,” which resulted in better performance than letting the CDN handle compression.

Some CDN providers offer their own Brotli compression at the edge. Major providers like Cloudflare now support end-to-end Brotli compression at the highest levels, recognizing the significant performance benefits. However, testing both approaches helps determine which configuration provides better performance for your specific setup.

Fix Common Problems

Several problems can occur during the Brotli installation process. Most issues relate to missing dependencies, permission problems, or version mismatches between nginx and the compiled modules.

When nginx fails to start after adding the Brotli modules, check that the module files exist in the correct location. Running ls -la /usr/lib/nginx/modules/ngx_http_brotli* should show both module files with proper permissions. If the files are missing, the compilation step might have failed silently.

If nginx configuration tests fail after adding Brotli directives, verify that the module load statements appear at the top of nginx.conf, before any other configuration blocks. The Brotli configuration directives must be placed inside the http block, not in server or location blocks.

When compression headers do not appear in HTTP responses, check several potential causes. First, verify that your test requests include the correct Accept-Encoding header. The file being tested must be larger than the minimum compression size (usually 1024 bytes) and must be listed in the brotli_types configuration.

Other Web Server Options

This guide covers nginx installation specifically because it requires manual compilation. Other web servers have different approaches for enabling Brotli compression.

Apache has mod_brotli available through package managers on most modern distributions, making installation simpler than nginx. The modules are pre-compiled, so you avoid the compilation process entirely. I will cover the complete Apache setup process in a separate tutorial for users who prefer that approach.

OpenLiteSpeed includes built-in Brotli support in the standard installation and can be enabled through the web interface without any compilation. This makes it the easiest option for users who want Brotli compression without technical setup or command-line work.

Nginx requires more work because it does not include Brotli modules in standard distributions. This approach keeps nginx lightweight but requires manual compilation for additional features. The process provides deeper understanding of how the modules work, but takes more time to implement properly.

Monitor Your Performance Gains

After implementing Brotli compression, monitor your website performance to verify the improvements work as expected. Google PageSpeed Insights provides before and after comparisons of Core Web Vitals metrics, with particular attention to Largest Contentful Paint and First Contentful Paint scores.

Server monitoring helps ensure that Brotli compression does not negatively impact server performance. CPU usage should remain similar to gzip compression levels, while memory usage might increase slightly. Network bandwidth usage typically decreases due to smaller file sizes being transmitted, which becomes especially noticeable during traffic spikes.

The performance improvements typically become noticeable within 24 hours as CDN caches populate with compressed content. Most sites see measurable improvements in user experience metrics and reduced bandwidth costs, making the initial setup effort worthwhile for production websites.

I have tested and applied these exact steps on multiple production servers with excellent results. The compilation process works reliably on Ubuntu 22.04 with HestiaCP, and the performance gains are immediately measurable. If you encounter any issues during your Brotli installation or need help optimizing your specific server configuration, feel free to comment below and I will be happy to help troubleshoot your setup.

Share This Article
FacebookWhatsappWhatsappRedditCopy Link
Joseph Matino
ByJoseph Matino
Follow:
I build custom applications and manage server infrastructure as CTO at Hostwek LTD, bringing six years of development experience to everything I do. Currently developing a cloud-based HMS and preparing our hosting platform for launch while expanding skills in Node.js, React, and AI. My infrastructure work includes Proxmox virtualization, custom Zabbix monitoring systems, and security implementations that keep systems secure and fast. Based in Kenya, I write about development workflows, server optimization, and PC gaming insights. Gaming helps maintain focus during long coding sessions.
Previous ArticleProxmox Ve 9.0 Brings Debian 13, Better Hardware Support, And Storage Snapshots. Complete Upgrade Guide For Bare Metal Servers.Proxmox VE 9.0: Better Bare Metal Performance with Debian 13
Subscribe
Notify of
guest
guest
0 Comments
Most Voted
NewestOldest
Inline Feedbacks
View all comments

What's New

Proxmox Disk Resize: LXC Containers and VMs Guide

Proxmox
7 hours ago

How to Install and Enable Brotli Compression on Nginx Ubuntu

Servers
1 week ago

Proxmox VE 9.0: Better Bare Metal Performance with Debian 13

Proxmox
2 weeks ago

How To Set Up FC-SAN With Proxmox VE 9.0 Snapshots

Proxmox
2 weeks ago

You Might also Like

13 Best Linux Server Distros With Gui 2024

13 Best Linux Server Distros with GUI: Worth Checking Out

Some of us enjoy the precision and control that comes with using the terminal, while…

Joseph Matino
11 months ago
How To Configure Whm Custom Nameservers With Cloudflare And Namecheap

How To Configure WHM Custom Nameservers With Cloudflare And Namecheap

Configuring WHM with custom nameservers can be tricky when you need to keep your primary…

Joseph Matino
12 months ago
How To Fix Curl: Unable To Get Local Issuer Certificate Error

How to Fix Curl: Unable to Get Local Issuer Certificate Error

When your computer shows the error “SSL Certificate Problem: Unable to Get Local Issuer Certificate”…

Joseph Matino
11 months ago
Assigning Multiple Ips In Almalinux 8 Manual Fix

Fix: How To Manually Configure Multiple IPs in AlmaLinux

Setting up a server with multiple IP addresses is a common task, often handled by…

Joseph Matino
1 year ago
Joseph Matino

Building digital solutions that don’t break at 3am. Passionate about custom applications, server management, A+ WordPress development, and sharing gaming insights. Creating reliable technology and honest content from Kenya.

Quicklinks

  • Terms & Conditions
  • Privacy Policy
  • Cookie Policy
  • Contact
  • About
  • Disclaimer
Hire Me

Connect

Follow Me
Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage optionsManage servicesManage {vendor_count} vendorsRead more about these purposes
Manage options
{title}{title}{title}
Manage your privacy

I use cookies and similar technologies to improve your experience on this blog. With your consent, I may process data such as how you interact with the site or unique device identifiers. If you choose not to consent or withdraw your consent, some features may not work as intended.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage optionsManage servicesManage {vendor_count} vendorsRead more about these purposes
Manage options
{title}{title}{title}
wpDiscuz