Install NGINX Brotli Module on Rocky Linux, AlmaLinux, CentOS & RHEL
by Danila Vershinin, , revisited on
dnf, yum or apt upgrades. It maintains the largest RPM repository of NGINX module packages and Varnish VMODs, with APT packages for Debian and Ubuntu.
Free to install; commercial production use requires a subscription.
Brotli is a modern compression algorithm that delivers 15-25% better compression ratios than gzip. With widespread browser support, enabling Brotli compression on your NGINX server is one of the easiest performance wins you can achieve.
This guide shows you how to install the NGINX Brotli module on RHEL-based systems including Rocky Linux, AlmaLinux, CentOS, and Amazon Linux using pre-built RPM packages from the GetPageSpeed repository. For Debian and Ubuntu users, check out our NGINX APT repository which provides the same modules.
Why Use Brotli Compression?
Brotli offers several advantages over traditional gzip compression:
- Better compression ratios: 15-25% smaller files at similar CPU cost
- Faster decompression: Browsers decompress Brotli faster than gzip
- Universal browser support: All modern browsers support Brotli (Chrome, Firefox, Safari, Edge)
Install NGINX Brotli Module
Step 1. Add GetPageSpeed Repository
For Rocky Linux, AlmaLinux, CentOS 8/9, or Fedora:
sudo dnf install -y https://extras.getpagespeed.com/release-latest.rpm
For CentOS/RHEL 7 or Amazon Linux 2:
sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm
Note: Free to install; commercial production use requires a subscription. Without one, a small license notice appears on HTML pages after 30 days.
Step 2. Install NGINX and Brotli Module
For Rocky Linux, AlmaLinux, CentOS 8/9, or Fedora:
sudo dnf install -y nginx nginx-module-brotli
For CentOS/RHEL 7 or Amazon Linux 2:
sudo yum -y install nginx nginx-module-brotli
Follow the installation prompt to import the GPG public key used for verifying packages.
Step 3. Enable Brotli Module in NGINX
The Brotli package includes two modules:
- ngx_http_brotli_filter_module.so – Compresses responses on-the-fly
- ngx_http_brotli_static_module.so – Serves pre-compressed
.brfiles
Add these lines at the top of /etc/nginx/nginx.conf:
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
For most use cases, you only need the filter module. The static module is useful if you pre-compress assets at build time for maximum compression.
Configure Brotli Compression
Create /etc/nginx/conf.d/brotli.conf with your compression settings:
brotli on;
brotli_comp_level 4;
brotli_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.ms-fontobject
application/wasm
application/x-font-opentype
application/x-font-truetype
application/x-font-ttf
application/x-javascript
application/xhtml+xml
application/xml
application/xml+rss
font/eot
font/opentype
font/otf
image/bmp
image/svg+xml
image/vnd.microsoft.icon
image/x-icon
text/cache-manifest
text/calendar
text/css
text/javascript
text/markdown
text/plain
text/vcard
text/vtt
text/x-component
text/xml;
Why compression level 4? Brotli’s sweet spot is level 4, where compression matches or exceeds gzip’s default level 6 while using less CPU time.
Reload NGINX to apply changes:
sudo systemctl reload nginx
Verify Brotli Compression Works
Using curl
Test from the command line:
curl -IL https://example.com -H "Accept-Encoding: br"
Look for Content-Encoding: br in the response headers.
Using Browser DevTools
- Open your site in Chrome or Firefox
- Open Developer Tools (F12)
- Go to the Network tab
- Reload the page
- Click any request and check Response Headers
- Look for
Content-Encoding: br
Pre-Compressed Brotli Files (Optional)
For maximum compression, pre-compress static assets at build time using Brotli’s highest compression level (11). The static module serves these .br files automatically.
Learn more in our guide on serving pre-compressed Brotli files with brotli_static.
PageSpeed Module Compatibility
If you use the PageSpeed NGINX module alongside Brotli, disable PageSpeed’s internal compression:
pagespeed HttpCacheCompressionLevel 0;
This allows the Brotli module to handle compression while PageSpeed handles optimization.
Going Further
For even better compression on modern systems, consider Zstd compression which offers faster compression speeds at similar ratios.
If your caching proxy or CDN mishandles the Vary header with multiple compression encodings, the NGINX compression vary module can fix broken Vary headers automatically.
Also check out how to install PageSpeed module for additional performance optimizations.
I already have Nginx installed. Will this reinstall it? I wonder if I’ll screw up any modules etc. I had installed with yum install Nginx command. Not sure if any special modules were installed. Can I therefore simply install the Brotli only?
I don’t know which repository you had installled Nginx from but most likely you’ll be offered upgrade to our repository’s Nginx. It should go smooth. If not sure, backup /etc/nginx first.
Which version of Nginx will this be?
Latest stable nginx 1.14.2 at present.
Thank you. Yes that’s what I have. I use certs from Let’s Encrypt and ssl etc. All is setup in Nginx.conf. Will all that’s remain intact if I copy the .conf files back after install? Or do I have to change this at all? Can I just leave Nginx as it is and only additionally install Brotli and maybe Headers More? Or will I have to reinstall everything?
It depends on repository where you installed nginx from. If from official stable nginx repository then you will only install the module. Either way, it will either work or not. Your nginx.conf will not be affected.
I installed nginx from generic yum. EPEL and REMI are in the list I think. Will I still be able to do this one above?
Nothing bad will happen if you just try to follow the provided instructions 🙂 Let me know how it goes.
Thank you, this is very helpful. I’ve installed it and it’s working. The content-encoding shows in Curl. However, questions:
In your sample encoding types you have not included JPG, PNG, SVG files. Is this intentional?
Secondly I have the gzip stuff from before. Should I comment it all out, or leave it and have Brotli as an additional parameter? Right now my nginx.conf has the following. I think the gzip stuff for MSIE6 etc may be not necessary anymore? But the listing of “gzip_types” has several file types that are not in your recommended Brotli list.
Thanks!
— NGINX.CONF —
SVG images are already included (there is
image/svg+xml), while JPEG and PNG are not compressible formats. You should keep gzip directives as GZip encoding will still be used for clients that support only GZip and have no knowledge about Brotli.“yum install nginx nginx-module-brotli”
No package nginx-module-brotli available.
Have you run
yum install https://extras.getpagespeed.com/release-latest.rpmSomehow when I run “yum install nginx” (step 2), it tries to install (nginx-1.16.0-1.el7.ngx.x86_64) which does exists and causes Error downloading packages:
1:nginx-1.16.0-1.el7.ngx.x86_64: [Errno 256] No more mirrors to try.
Any advises?
Please provide complete command you run with complete output.
Installing this broke nginx for me. Any ideas?
running
sudo nginx -tcomplains about conflicts with a lot of modules, such as:and
Hi Scott,
Try running
yum list installed | grep nginxand post the output here.Without looking, it seems that you have installed NGINX from EPEL repository (?) or elsewhere.
… Which is more or less impossible though, because the
nginx-module-brotlihas a hard dependency on newer (than at least EPEL provides) NGINX version.I did indeed install nginx from epel, pretty new CentOS install from last week. Looks like when I installed with the instructions above it updated to nginx from your repo, but all my modules are still from the epel nginx version?
Here’s my results from
yum list installed | grep nginxThe official NGINX package (the one you installed from our repo is the exact copy of it) does not obsolete all NGINX-related module packages from EPEL. You can cleanup the EPEL NGINX packages via something like:
yum remove $(yum list installed | grep 'nginx.*@epel' | awk '{ print $1 }')Thanks, removed the incompatible packages and all seems to be working well.