Installing and connecting the Brotli compression module for NGINX in Centos 7

Brotli is a new compression algorithm that is now widely supported in many browsers. The brotli compression method is based on the modern version of the LZ77 algorithm. Compared to the classic deflate algorithm (mid-1990s, ZIP, gzip), brotli typically achieves 20% higher compression for text files while maintaining similar compression and decompression rates …

Add the GetPageSpeed ​​repository

[[email protected]]# yum -y install https://extras.getpagespeed.com/release-el7-latest.rpm

NGINX installation was covered earlier

Install the module

[[email protected]]# yum -y install nginx-module-nbr

Let’s open the main NGINX config and connect the module

[[email protected]]# nano /etc/nginx/nginx.conf
...
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
load_module "modules/ngx_http_brotli_filter_module.so";
load_module "modules/ngx_http_brotli_static_module.so";
...

We will enable Brotli compression in all our sites, for this we will create a file with the appropriate content

[[email protected]]# nano /etc/nginx/conf.d/brotli.conf
brotli on;
brotli_types text/xml
       image/svg+xml
       application/x-font-ttf
       image/vnd.microsoft.icon
       application/x-font-opentype
       application/json
       font/eot
       application/vnd.ms-fontobject
       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;
brotli_comp_level 4;

Checking the NGINX configuration for errors and reloading it

[[email protected]]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[[email protected]]# systemctl restart nginx

Check if Brotli compression is enabled on the site

[[email protected]]# curl -IL https://itdraft.ru -H "Accept-Encoding: br"
...
Content-Encoding: br
Sidebar