Google Cloud Compute Engine

Install Nginx with Brotli on Ubuntu 18.04 – Google Cloud

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

Install Brotli with Nginx on Ubuntu 18.04 – Google Cloud. Brotli is a lossless compression algorithm which is developed by Google for the compression of static resources like HTML, JS, CSS and JSON.

In this guide you are going to learn how to install Brotli with Niginx on Ubuntu server. This setup is tested on Google Cloud and it works well with AWS or Azure or any cloud servers or VPS and dedicated servers running Ubuntu.


Install Nginx with Brotli Module

Here you will install Nginx and ngx_brotli an Nginx module by adding the Nginx HDA repository.

sudo apt-add-repository -y ppa:hda-me/nginx-stable

Update the package index for the package to become available.

sudo apt update

Now you can install Nginx, Brotli and the Nginx Brotli module using the following command.

sudo apt install brotli nginx nginx-module-brotli

Install Let’s Encrypt SSL

Brotli works only with HTTPS, so you need to install SSL certificate.

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python-certbot-nginx

Now we have installed Certbot by Let’s Encrypt for Ubuntu 18.04, run this command to receive your certificate and install it.

sudo certbot --nginx --agree-tos --redirect -m EMAIL -d DOMAIN_NAME -d www.DOMAIN_NAME

The Certbot client will automatically generate the new certificate for your domain and updates your configuration.

Enable Nginx Brotli Module

Now you can enable the Nginx Brotli module by including the ngx_http_brotli_filter_module and the ngx_http_brotli_static_module in your nginx.conf.

Edit your main Nginx configuration and the below lines after include /etc/nginx/modules-enabled/*.conf; so that it looks like below.

sudo nano /etc/nginx/nginx.conf
include /etc/nginx/modules-enabled/*.conf;

load_module modules/;
load_module modules/;

Now open your site configuration for Nginx and add the below lines inside the server block.

server {
brotli on;
brotli_comp_level 6;
brotli_types text/xml image/svg+xml application/x-font-ttf image/ application/x-font-opentype application/json font/eot application/ application/javascript font/otf application/xml application/xhtml+xml text/javascript  application/x-javascript text/plain application/x-font-truetype application/xml+rss image/x-icon font/opentype text/css image/x-win-bitmap;

Now you can check your configuration and restart Nginx for the changes to take effect.

sudo nginx -t
sudo service nginx restart

Verify Brotli Installation

Now go to your browser and point it to your domain name. Also open the Inspect Element by hitting F12 or right-click and select Inspect Element. Navigate to Network and load your website. You will see something similar to the one below.

Install Nginx with Brotli

If you notice the Content Encoding under Response headers you will see br which indicates your website’s static resources are compressed using Brotli.

Get your Professional Google Cloud Architect certificate with this easy to learn course now.


Now you have learned how to install Nginx and configure Brotli compression on Ubuntu on Google Cloud.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

1 Comment

  1. Many thanks for all the awesome articles. I am really enjoying the information and the way you are explaining how to get things up and running. Is it possible to send you some suggestions for other installations / howtos ?

    For n ow enjoy your day!

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.