How To Install Brotli Module for Nginx on Ubuntu 20.04 LTS

Install Brotli Module for Nginx on Ubuntu 20.04

In this tutorial, we will show you how to install the Brotli module for Nginx on Ubuntu 20.04 LTS. For those of you who didn’t know, Brotli is a high-performance, lossless compression algorithm developed and maintained by Google. It can be used by webservers to compress files like .html and .css files and increase the perforce of websites and reduce their bandwidth requirements.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step enabling Brotli Compression on Nginx. You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.

Install Brotli Module for Nginx on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Installing Nginx on Ubuntu 20.04.

Nginx is available in the default Ubuntu repositories. To install it run the following command:

sudo apt install nginx

Once the installation is completed, run the commands to enable Nginx to automatically startup when your server starts:

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Step 3. Installing Brotli Module for Nginx.

Now we run the following command to download and install the Nginx Static Brotli module:

cd /etc/nginx/modules
wget http://dl1.centos-webpanel.com/files/nginx/modules/nginx-brotli-modules.zip
unzip nginx-brotli-modules.zip
rm -rf nginx-brotli-modules.zip

Step 4. Configure Nginx.

We create the configuration so that NGINX will use the Brotli module:

nano /etc/nginx/nginx.conf

Add these lines on top of the nginx.conf:

load_module "modules/ngx_http_brotli_filter_module.so";
load_module "modules/ngx_http_brotli_static_module.so";

Look similar to this:

load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
.............................................

Now, add the Brotli config:

# /etc/nginx/conf.d/brotli.conf# Enable Brotlibrotlion;brotli_staticon;brotli_comp_level 6;# File types to compressbrotli_types application/atom+xml application/javascript application/json application/rss+xmlapplication/vnd.ms-fontobject application/x-font-opentype application/x-font-truetypeapplication/x-font-ttf application/x-javascript application/xhtml+xml application/xmlfont/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.iconimage/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;

Next, start the Nginx service using the following command:

sudo systemctl restart nginx

Step 5. Testing Brotli Module.

Now, verify whether the Brotli module is enabled or not by running the following command:

curl -H 'Accept-Encoding: br' -I http://localhost

Output:

HTTP/2 200
date: Thu, 01 Jun 2021 12:45:55 GMT
server: Apache
strict-transport-security: max-age=15552000; includeSubDomains
last-modified: Wed, 20 Mya 2021 18:53:30 GMT
etag: "15e8-5a2cmeilanabf77-br"
accept-ranges: bytes
vary: Accept-Encoding
content-encoding: br
content-length: 1539
content-type: text/html

Congratulations! You have successfully installed the Brotli module. Thanks for using this tutorial for installing enabling Brotli Compression on Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official Nginx website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!