How to enabling Brotli Compression on Nginx?

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.


Step 1 :

Check Nginx web server/Proxy is already installed on your server


Step 2 :

Download and install Nginx Static Brotli module:

cd /etc/nginx/modules
rm -rf 


Step 3 :

Now add nginx module configuration on "nginx.conf":

nano /etc/nginx/nginx.conf


Now add these lines on top of the nginx.conf:

load_module "modules/";
load_module "modules/";


Now add brotli compression configuration in nginx.conf file in

http {

section and before http closing




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


Save the file and restart nginx :

service nginx restart
systemctl restart nginx


Go to this site for the checks :</a.


For the advanced user you can check content-encoding via http header:

HTTP/2.0 200 OK
server: nginx
content-type: text/html; charset=UTF-8
vary: Accept-Encoding, Cookie
content-encoding: br    


Was this answer helpful? 0 Users Found This Useful (0 Votes)