Skip to main content

NGINX

Brotli NGINX Rocky Linux 10: Installation Guide

by ,


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

Brotli NGINX Rocky Linux 10 installation is straightforward with the GetPageSpeed repository. This modern compression algorithm delivers significantly better compression ratios than gzip, reducing text-based content by 15-25% more and resulting in faster page loads and reduced bandwidth costs.

This comprehensive guide walks you through installing and configuring Brotli NGINX on Rocky Linux 10, AlmaLinux 10, and other Enterprise Linux 10 distributions. You will learn optimal configuration settings and how to verify everything works correctly. By the end, you will have Brotli NGINX Rocky Linux 10 compression fully operational on your server.

Why Choose Brotli Over Gzip

Brotli is a modern compression algorithm developed by Google that offers several advantages over traditional gzip compression:

  • Better compression ratios: Brotli typically achieves 15-25% smaller file sizes compared to gzip at equivalent CPU usage
  • Optimized for web content: The algorithm was specifically designed for HTTP compression with a built-in dictionary of common web patterns
  • Wide browser support: All modern browsers including Chrome, Firefox, Safari, and Edge support Brotli encoding
  • Backward compatible: Servers can serve gzip to older clients while using Brotli for modern browsers

For websites serving lots of JavaScript, CSS, and HTML, Brotli compression can noticeably improve page load times. This is especially valuable for users on mobile networks where every kilobyte matters. Combining Brotli with proper browser caching maximizes performance gains.

Prerequisites

Before installing Brotli NGINX Rocky Linux 10 packages, ensure you have:

  • Rocky Linux 10, AlmaLinux 10, RHEL 10, or Oracle Linux 10
  • Root or sudo access to the server
  • NGINX installed (or we will install it in this guide)

The GetPageSpeed repository provides pre-built Brotli modules that are fully compatible with SELinux and integrate seamlessly with the standard NGINX package.

Installation

Step 1: Configure GetPageSpeed Repository

The GetPageSpeed repository provides enterprise-grade NGINX modules for RHEL-based distributions. Install the repository with a single command:

sudo dnf -y install https://extras.getpagespeed.com/release-latest.rpm

This repository contains over 100 NGINX modules, all built and tested for Rocky Linux 10 and other EL10 distributions.

Step 2: Install NGINX

If you do not already have NGINX installed, install it from the GetPageSpeed repository:

sudo dnf -y install nginx
sudo systemctl enable --now nginx

This installs NGINX 1.28 (or the latest stable version) with full HTTP/3 and QUIC support.

Step 3: Install the Brotli Module

Install the NGINX Brotli module package:

sudo dnf -y install nginx-module-brotli

After installation, the package displays instructions for enabling the module:

----------------------------------------------------------------------

The Brotli dynamic modules for nginx have been installed.
To enable these modules, add the following to /etc/nginx/nginx.conf
and reload nginx:

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

----------------------------------------------------------------------

The package installs two modules:

  • ngx_http_brotli_filter_module: Compresses responses on-the-fly
  • ngx_http_brotli_static_module: Serves pre-compressed .br files

Step 4: Enable the Brotli Module

Add the module loading directives at the very top of your NGINX configuration file, before the events block:

# /etc/nginx/nginx.conf
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

user nginx;
worker_processes auto;
# ... rest of configuration

Step 5: Configure Brotli Compression

Create a dedicated configuration file for Brotli settings:

sudo tee /etc/nginx/conf.d/brotli.conf > /dev/null << 'EOF'
# Brotli compression configuration
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types
    text/plain
    text/css
    text/xml
    text/javascript
    application/javascript
    application/json
    application/xml
    application/rss+xml
    application/atom+xml
    image/svg+xml
    font/ttf
    font/otf
    font/woff
    font/woff2;
EOF

Now test and reload the NGINX configuration:

sudo nginx -t && sudo systemctl reload nginx

You should see:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Understanding Brotli Configuration Directives

Let us examine each Brotli directive to understand how they affect compression behavior.

brotli

brotli on;

This directive enables or disables Brotli compression. When set to on, NGINX will compress responses for clients that send Accept-Encoding: br in their request headers.

brotli_comp_level

brotli_comp_level 6;

The compression level ranges from 0 (no compression) to 11 (maximum compression). Higher levels produce smaller files but require more CPU time:

Level Compression CPU Usage Recommendation
1-3 Low Very Low Real-time streaming
4-5 Medium Low High-traffic sites
6 Good Medium Recommended default
7-9 High High Pre-compression only
10-11 Maximum Very High Static assets only

We recommend level 6 for on-the-fly compression as it provides excellent compression ratios without excessive CPU overhead.

brotli_static

brotli_static on;

When enabled, NGINX first checks for pre-compressed .br files before compressing on-the-fly. For example, when a client requests /style.css, NGINX looks for /style.css.br and serves it directly if found.

Options for this directive:

  • off – Disabled (default)
  • on – Serve .br files if they exist
  • always – Always serve .br files (for pre-compressed-only setups)

brotli_types

brotli_types text/plain text/css application/javascript application/json;

Specifies which MIME types should be compressed. Only text-based content benefits from Brotli compression. Never include already-compressed formats like JPEG, PNG, or WebP.

brotli_min_length

brotli_min_length 256;

Sets the minimum response size for compression. Responses smaller than this value are sent uncompressed. The default is 20 bytes, but 256 bytes is more practical since very small files have minimal compression benefit.

brotli_buffers

brotli_buffers 16 8k;

Configures the number and size of buffers used for compression. The default values work well for most deployments.

brotli_window

brotli_window 512k;

Sets the Brotli sliding window size. Larger windows can improve compression but use more memory. Valid values range from 1k to 16m. The default of 512k is suitable for most use cases.

Verification

After configuring Brotli NGINX Rocky Linux 10, verify that compression is working correctly.

Using curl

Test Brotli compression with curl by sending the Accept-Encoding: br header:

curl -sI -H "Accept-Encoding: br" http://localhost/ | grep -i content-encoding

You should see:

Content-Encoding: br

Comparing Compression Ratios

Create a test file and compare compressed versus uncompressed sizes:

# Create a 100KB test file
dd if=/dev/zero bs=1024 count=100 2>/dev/null | tr '\0' 'A' > /usr/share/nginx/html/test.txt

# Uncompressed size
curl -s -o /dev/null -w '%{size_download}\n' http://localhost/test.txt

# Brotli compressed size
curl -s -o /dev/null -H "Accept-Encoding: br" -w '%{size_download}\n' http://localhost/test.txt

For repetitive content, Brotli achieves extremely high compression ratios, often reducing files to just a few bytes.

Browser Verification

Open your browser developer tools (F12), navigate to the Network tab, and inspect the Content-Encoding header for your responses. Modern browsers display br for Brotli-compressed responses.

Creating Pre-compressed Brotli Files

For maximum performance, pre-compress your static assets using the Brotli command-line tool:

# Install brotli CLI tool
sudo dnf -y install brotli

# Compress static files with maximum compression
brotli -k -q 11 /var/www/html/assets/*.css
brotli -k -q 11 /var/www/html/assets/*.js

The -k flag keeps the original file, and -q 11 uses maximum compression since CPU time does not matter for offline compression.

With brotli_static on, NGINX automatically serves these pre-compressed files to clients that support Brotli, eliminating runtime compression overhead entirely.

Using Brotli Alongside Gzip

For maximum compatibility, configure both Brotli and gzip compression. NGINX will automatically choose the best encoding based on what the client supports:

# /etc/nginx/conf.d/compression.conf

# Brotli compression (preferred for modern browsers)
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types
    text/plain text/css text/xml text/javascript
    application/javascript application/json application/xml
    application/rss+xml application/atom+xml
    image/svg+xml font/ttf font/otf font/woff font/woff2;

# Gzip compression (fallback for older clients)
gzip on;
gzip_vary on;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types
    text/plain text/css text/xml text/javascript
    application/javascript application/json application/xml
    application/rss+xml application/atom+xml
    image/svg+xml;

When a client sends Accept-Encoding: br, gzip, NGINX prefers Brotli. Clients that only support gzip receive gzip-compressed responses.

Common Issues and Troubleshooting

Brotli Not Working

Symptom: Responses do not show Content-Encoding: br

Solutions:

  1. Verify the module files exist: ls /usr/lib64/nginx/modules/ngx_http_brotli_*
  2. Check the module is configured: nginx -T 2>&1 | grep brotli
  3. Ensure nginx -t passes without errors
  4. Check that brotli on is in the correct context (http, server, or location)
  5. Ensure the MIME type is listed in brotli_types
  6. Confirm the client sends Accept-Encoding: br header

Module Not Found Error

Symptom: nginx: [emerg] unknown directive "brotli"

Solution: The load_module directives must appear before any other configuration:

# CORRECT - at the very top of nginx.conf
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

events {
    worker_connections 1024;
}

High CPU Usage

Symptom: CPU spikes during high traffic

Solutions:

  1. Lower brotli_comp_level to 4 or 5
  2. Use brotli_static on with pre-compressed files
  3. Increase brotli_min_length to skip small responses

SELinux Compatibility

The nginx-module-brotli package from GetPageSpeed is fully compatible with SELinux. No additional configuration or policy modifications are required. The module loads and operates correctly with SELinux in enforcing mode.

Performance Comparison: Brotli vs Gzip

Here are typical results compressing a 100KB minified JavaScript file:

Algorithm Level Size Time Savings
None 100 KB 0 ms 0%
Gzip 6 32 KB 3 ms 68%
Brotli 6 27 KB 4 ms 73%
Brotli 11 24 KB 45 ms 76%

Brotli at level 6 produces files approximately 15% smaller than gzip at level 6, with only marginally more CPU usage. For pre-compressed static files, Brotli level 11 can save an additional 8% over real-time Brotli.

Complete Production Configuration

Here is a complete, production-ready NGINX configuration with Brotli compression:

# /etc/nginx/nginx.conf
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    sendfile on;
    keepalive_timeout 65;

    # Brotli compression
    brotli on;
    brotli_comp_level 6;
    brotli_min_length 256;
    brotli_static on;
    brotli_types
        text/plain
        text/css
        text/xml
        text/javascript
        application/javascript
        application/json
        application/xml
        application/rss+xml
        application/atom+xml
        image/svg+xml
        font/ttf
        font/otf
        font/woff
        font/woff2;

    # Gzip fallback
    gzip on;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_min_length 256;
    gzip_types
        text/plain text/css text/xml text/javascript
        application/javascript application/json application/xml
        image/svg+xml;

    include /etc/nginx/conf.d/*.conf;
}

Test and apply:

sudo nginx -t && sudo systemctl reload nginx

For more NGINX optimization guides, see these related articles:

Conclusion

Brotli NGINX Rocky Linux 10 setup provides a significant upgrade over traditional gzip compression. With the GetPageSpeed repository, installation takes just a few commands, and the pre-built packages ensure full compatibility with SELinux and the standard NGINX distribution.

By configuring Brotli at compression level 6 alongside gzip as a fallback, you achieve optimal compression for modern browsers while maintaining compatibility with older clients. For static assets, pre-compressing files with Brotli level 11 and using brotli_static on eliminates runtime CPU overhead entirely.

The bandwidth savings from Brotli compression translate directly to faster page loads, better Core Web Vitals scores, and reduced hosting costs. For any production NGINX deployment on Rocky Linux 10, enabling Brotli compression is a straightforward optimization with immediate benefits.

D

Danila Vershinin

Founder & Lead Engineer

NGINX configuration and optimizationLinux system administrationWeb performance engineering

10+ years NGINX experience • Maintainer of GetPageSpeed RPM repository • Contributor to open-source NGINX modules

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.