Brotli compression reduces the size of HTML, CSS, JavaScript, JSON, XML, and SVG responses before Apache sends them to the client, which cuts bandwidth use and shortens transfer time on slower links.

Apache handles Brotli through mod_brotli. When a client advertises Accept-Encoding: br, the BROTLI_COMPRESS output filter compresses only the configured MIME types, then returns Content-Encoding: br and Vary: Accept-Encoding so caches keep compressed and uncompressed responses separate.

Current Debian and Ubuntu Apache packages already ship the mod_brotli module file and the brotli.load stub, so the job is usually enabling the built-in module and adding a conf-available rule set instead of building a third-party module. Compression still costs CPU and can contribute to BREACH-style side-channel exposure on HTTPS responses that reflect secrets, so keep the filter list focused on text responses that should be compressed.

Steps to enable Brotli compression in Apache:

  1. Enable the built-in brotli module.
    $ sudo a2enmod brotli
    Enabling module brotli.
    To activate the new configuration, you need to run:
      systemctl restart apache2

    Current Debian and Ubuntu packages provide /usr/lib/apache2/modules/mod_brotli.so with apache2-bin and /etc/apache2/mods-available/brotli.load with apache2. There is no separate libapache2-mod-brotli package on current releases.

  2. Create a Brotli rules file in /etc/apache2/conf-available/brotli.conf.
    $ sudo tee /etc/apache2/conf-available/brotli.conf >/dev/null <<'EOF'
    <IfModule mod_brotli.c>
        BrotliCompressionQuality 5
        BrotliAlterETag AddSuffix
        AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/javascript application/javascript application/json application/xml text/xml application/xhtml+xml application/rss+xml application/atom+xml image/svg+xml
    </IfModule>
    EOF

    Keep the filter list on text-based responses. Formats such as JPEG, PNG, WebP, AVIF, ZIP, or MP4 are already compressed and usually waste CPU when passed through Brotli again.

  3. Enable the Brotli configuration snippet.
    $ sudo a2enconf brotli
    Enabling conf brotli.
    To activate the new configuration, you need to run:
      systemctl reload apache2
  4. Validate the Apache configuration syntax, then restart the service so the newly enabled module is loaded.
    $ sudo apachectl configtest
    Syntax OK
    
    $ sudo systemctl restart apache2

    Use a restart after a2enmod brotli. Later edits to only /etc/apache2/conf-available/brotli.conf can usually be applied with a reload instead.

  5. Verify that mod_brotli is loaded.
    $ apachectl -M 2>/dev/null | grep brotli
     brotli_module (shared)

    apache2ctl -M returns the same module list on Debian and Ubuntu systems that prefer the apache2ctl wrapper name.

  6. Confirm that a text response is served with Brotli compression.
    $ curl -sSI -H 'Accept-Encoding: br' -H 'Host: example.com' http://127.0.0.1/
    HTTP/1.1 200 OK
    Date: Wed, 08 Apr 2026 04:50:11 GMT
    Server: Apache/2.4.58 (Ubuntu)
    Last-Modified: Wed, 08 Apr 2026 04:50:09 GMT
    ETag: "29af-64eeba271beca-br"
    Accept-Ranges: bytes
    Vary: Accept-Encoding
    Content-Encoding: br
    Content-Length: 2722
    Content-Type: text/html

    If Content-Encoding: br is missing, test a text URL that matches the active virtual host. Binary assets and content types outside the AddOutputFilterByType list will not be compressed.