Web Servers

How To Enable Brotli Compression on Nginx CWP

In this article, we will learn how to enable Brotli compression on Nginx CWP.

Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods. It is similar in speed with deflate but offers more dense compression.

Prerequisites:

1. Check Nginx web server is installed.

2. Download and install Nginx Static Brotli module

Follow these steps:

# 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

3. Add module in Nginx configuration file:

Edit Nginx configuration file using your favorite editor:

# vi /etc/nginx/nginx.conf

Add following lines on the of the nginx.conf file:

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

Next add brotli compression configuration in nginx.conf file in http{} before closing section

#brotli
brotli on;
brotli_comp_level 6;
brotli_static 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;

Save and exit

4. Restart Nginx service

# systemctl restart nginx

That’s it.

We have seen how our support engineers enable Brotli compression on Nginx CWP.

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles