Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Web Servers»Apache»How To Enable Brotli Compression in Apache

    How To Enable Brotli Compression in Apache

    By RahulJuly 1, 20212 Mins Read

    Just like Gzip, Brotli is also a generic-purpose compression algorithm developed by Google. It compresses data using a combination of modern technologies and algorithms. It is similar in speed to deflate but provides higher compression. Brotli compression is supported by all the major browsers like Chrome, Firefox, Safari, Edge.

    Advertisement

    The Brotli compression is opted by the top tech fortunes like Cloudflare etc. This is the reason, we recommend switching to brotli from the old deflate data compression algorithm.

    This tutorial helps you to enable brotli compression in the Apache webserver.

    Prerequisites

    Shell access to your server with sudo privileged account.

    We assume that you already have a running Apache server. Also created a virtual host for the web application.

    Step 1 – Installing Brotli

    First, install the brotli package on your system. For the Ubuntu and Debian systems, it’s available in the default repositories.

    Open a terminal and type:

    sudo apt install brotli -y 
    

    This will install the required package containing the algorithm files on your system.

    Step 2 – Configure Brotli with Apache

    The Apache server contains the Brotli module default. You can enable the brotli module in Apache with the following command.

    sudo a2enmod brotli 
    

    Next, you have to configure the Apache virtual host to enable compression with brotli. You need to add the below code in the virtual host configuration file.

    1
    2
    3
    <IfModule mod_brotli.c>
        AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
    </IfModule>

    After enabling the brotli compression the Virtual host configuration file looks like below:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <VirtualHost *:80>
          ServerAdmin webmaster@localhost
          ServerName example.com
          DocumentRoot /var/www/
     
          <IfModule mod_brotli.c>
                AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
          </IfModule>
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

    Save the configuration file and close it. Then reload the Apache service to apply changes.

    sudo systemctl restart apache2 
    

    That’s it. You have successfully enabled brotli compression in the Apache server.

    Step 3 – Test Compression

    Access your web application in a browser and check headers value in the browser console. You need to search for the Content-Encoding value. It must contain br as value, which denotes that the web page is compressed with brotli compression.

    The command line heroes can also use curl command to access the header values as below:

    curl -I -H 'Accept-Encoding: br' http://example.com 
    

    You will see the result below.

    HTTP/1.1 200 OK
    Date: Thu, 01 Jul 2021 06:26:54 GMT
    Server: Apache/2.4.41 (Ubuntu)
    Upgrade: h2,h2c
    Connection: Upgrade
    Last-Modified: Fri, 05 Feb 2021 08:55:44 GMT
    ETag: "33-5ba92fc4cecdf-br"
    Accept-Ranges: bytes
    Vary: Accept-Encoding
    Content-Encoding: br
    Content-Length: 46
    Content-Type: text/html
    

    Check for the value of Content-Encoding option.

    Conclusion

    This tutorial helped you to configure Brotli compression in the Apache webserver.

    Apache compression gzip
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Comparing Apache MPM Worker and Prefork: Which is Right for Your Application

    An Introduction to Apache MPM (Multi-Processing Modules)

    How to Install Apache (httpd) on RHEL & CentOS Stream 9

    View 2 Comments

    2 Comments

    1. derek on March 11, 2022 8:48 pm

      why am i getting “ERROR: Module brotli does not exist!” after a2enmod brotli?

      Reply
    2. moe on September 7, 2021 11:47 pm

      I was trying to configure brotli to work with my website ,,,it just worked great.!Thanks

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.