How to Install Nginx with Brotli Compression on Ubuntu 20.04
How to Install Nginx with Brotli Compression on Ubuntu 20.04
Author: Łukasz Bodziony
Email: lukasz@bodziony.net.pl
DevOps Services: bodziony.net.pl
Published: June 2025
Introduction
Brotli is a modern compression algorithm developed by Google. When used with Nginx, it can significantly reduce file sizes and improve website performance. This tutorial, written by Łukasz Bodziony, walks you through installing and configuring Nginx with Brotli on Ubuntu 20.04.
Prerequisites
- Ubuntu 20.04 LTS server
- Sudo/root privileges
- Basic command-line knowledge
💡 For optimal performance, consider a reliable VPS from NetCloud24.
Step 1: Remove Default Nginx
sudo apt remove nginx nginx-common -y
Step 2: Install Required Packages
sudo apt update
sudo apt install -y build-essential zlib1g-dev libpcre3 libpcre3-dev unzip uuid-dev
Step 3: Download Brotli and Nginx Source Code
cd /usr/local/src
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli && git submodule update --init
cd ..
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar -xzvf nginx-1.24.0.tar.gz
cd nginx-1.24.0
Step 4: Compile Nginx with Brotli Support
./configure --with-http_ssl_module --add-module=../ngx_brotli
make
sudo make install
Step 5: Configure Brotli in Nginx
brotli on;
brotli_comp_level 6;
brotli_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
Save changes and start Nginx:
sudo /usr/local/nginx/sbin/nginx
Step 6: Verify Brotli Compression
curl -H "Accept-Encoding: br" -I https://yourdomain.com
If Brotli is working, you’ll see: Content-Encoding: br
Conclusion
You've now compiled and enabled Brotli compression in Nginx on Ubuntu 20.04. This setup enhances performance by reducing page load time and bandwidth usage. Article prepared by Łukasz Bodziony.
- 💼 DevOps Services: bodziony.net.pl
- 📧 Contact: lukasz@bodziony.net.pl
- 🚀 Host it on: NetCloud24 VPS Linux
Comments
Post a Comment