Key Architecture Takeaways
- ›Point 1: Production blueprint for Install and config Brotli Compression with Apache on Linux infrastructure.
- ›Point 2: Covers root privilege management, daemon supervision via systemd, and secure file operations.
- ›Point 3: Applies to LTS releases (Ubuntu 24.04/22.04 LTS, Debian 12 Bookworm).
Enterprise Compatibility Update (2026 / LTS)
While these fundamentals apply directly to existing deployments, modern installations on Ubuntu 22.04 and 24.04 LTS use systemd-resolved, nftables for packet filtering, and modern OpenSSH 9+ with Ed25519 cryptography.
Why Brotli Matters for Web Performance
Today's world is growing very fast and everyone is in a hurry! According to a Google study, 40% of people abandon a website that takes more than 3 seconds to load and a 1-second delay in page response can result in a 7% reduction in conversions. Yes, every second matters! hence Brotli comes into effect to speed up your website.
Just like Gzip, Brotli is also a generic-purpose compression algorithm developed by Google. It compresses data using a combination of modern technologies and algorithms. It is similar in speed to deflate but provides higher compression. Brotli compression is supported by all the major browsers like Chrome, Firefox, Safari, Edge.
In this Article we are going to configure Brotli Compressor Mechanism with Apache Web Server.
Prerequisites & Baseline Setup
- ›Need a
sudoprivileged account on Ubuntu 20.04 / 22.04 / 24.04 LTS or Debian 12. - ›Assumed that you have an Apache webserver running with a VirtualHost serving web content.
- ›Ensure ports 80 and 443 are reachable and not blocked by local firewalls.
We assume that you have an existing web server with Apache in order to do the experiment, and if you are in a production environment then I strongly recommend to make a backup your files before that.
Step 1: Install and Enable mod_brotli
Go ahead and install the system Brotli binaries:
sudo apt update && sudo apt install -y brotliAfter installing Brotli, enable the native Apache mod_brotli module:
sudo a2enmod brotliRestart Apache2 in order to activate the module:
sudo systemctl restart apache2Step 2: Configure VirtualHost Directives
Now open up your Apache VirtualHost configuration file (/etc/apache2/sites-available/your-site.conf):
sudo nano /etc/apache2/sites-available/myapp1.confInside your configuration file, place the Brotli compression rules inside the <VirtualHost> block:
<VirtualHost *:80>
ServerName myapp1.com
ServerAdmin admin@myapp1.com
DocumentRoot /var/www/html/wordpress/
<Directory /var/www/html/wordpress>
Options Indexes MultiViews
AllowOverride All
Require all granted
</Directory>
# ── Brotli Compression Directives ──────────────────────────────
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml
BrotliCompressionQuality 6
</IfModule>
# ───────────────────────────────────────────────────────────────
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>After saving the configuration, test Apache syntax and restart the service:
sudo apache2ctl configtest
sudo systemctl restart apache2Step 3: Verify Compression with cURL
Now verify that Apache is serving Brotli-compressed responses by passing the Accept-Encoding: br header with curl:
curl -I -H "Accept-Encoding: br" http://myapp1.comThe response headers will confirm active Brotli negotiation:
HTTP/1.1 200 OK
Date: Mon, 09 Aug 2021 06:50:56 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Encoding: br
Content-Type: text/html; charset=UTF-8Production Hardening & Best Practices
- [01]Quality Setting: Use
BrotliCompressionQuality 5or6for on-the-fly compression. Higher levels (up to 11) yield smaller files but significantly spike CPU latency. - [02]Pre-Compression: For static assets (CSS, JS bundles), pre-compress with
brotli -k -q 11 filename.jsduring CI/CD build pipelines and serve withFallbackResourceor Nginx static modules. - [03]MIME Whitelist: Only compress compressible text types (
text/*,application/json,application/javascript). Never apply Brotli to binary formats like JPEG, PNG, or MP4, which only wastes CPU cycles.

