NGINX / Server Setup

How to install Brotli NGINX module in Plesk for CentOS/RHEL 7 or 8

by , , revisited on


We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install NGINX, Varnish, and lots of useful modules for them, this is your one-stop repository to get all performance-related software.
You have to maintain an active subscription in order to be able to use the repository!

Plesk is a modern alternative to cPanel and provides a web interface for managing websites in bulk.

Although my personal view on control panels is beyond negative, I’ve spent some time looking at how to get a missing feature for Plesk – Brotli compression.

Why did I bother? I’ve had a repository subscriber asking whether NGINX modules are compatible with Plesk.

My answer was that “Plesk is likely to have their own repo”.
Later this was confirmed and I simply got curious whether things with Plesk can be improved with supplementary packaging effort.

And so, meet Brotli NGINX module for Plesk. Let’s go through some quick steps on bringing Brotli compression to Plesk.

Pre-requisites

  • CentOS/RHEL 7 or CentOS/RHEL 8
  • Latest Plesk
  • 2 minutes of free time

Step 1. Install GetPageSpeed repository

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

Needless to say, you have to subscribe.

Step 2. Install Brotli NGINX module

sudo yum install sw-nginx-module-nbr

Step 3. Enable Brotli module

sudo plesk sbin nginx_modules_ctl --enable brotli 

PageSpeed module compatibility

As it stands, the PageSpeed NGINX module does not support Brotli compression internally.
You can use if together with the Brotli NGINX module, but you will have to disable internal PageSpeed compression by editing /etc/nginx/nginx.conf and specifying pagespeed HttpCacheCompressionLevel 0;, e.g.:

http {
    pagespeed HttpCacheCompressionLevel 0;
    ...
}

This will ensure that the Brotli compression works, at the cost of storing optimized assets uncompressed.

Step 4. Enable Brotli compression for all websites

Create the file /etc/nginx/conf.d/brotli.conf with contents:

brotli on;
brotli_types text/xml
       image/svg+xml
       application/x-font-ttf
       image/vnd.microsoft.icon
       application/x-font-opentype
       application/json
       font/eot
       application/vnd.ms-fontobject
       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;
brotli_comp_level 4;
sudo nginx -t && sudo systemctl restart nginx

(we have to restart NGINX as opposed to reloading its config due to a bug in Plesk).

As an alternative to enabling Brotli for all websites, you can enable Brotli compression for a specific website only.
Open the website’s settings in Plesk admin and navigate to its Hosting & DNS -> Apache & nginx Settings .
Scroll down to “Additional nginx directives” and paste in the same lines as above.
Then similarly, restart NGINX.

Welcome to NGINX with Brotli support 🙂

Verify Brotli compression works

Via Command-Line

It’s easiest to launch the Terminal app (if you have OS X) and check if your NGINX emits Brotli encoded responses.

Simply use curl like this:

curl -IL https://example.com -H "Accept-Encoding: br"

As long as you see the response includes Content-Encoding: br, it means that NGINX properly handles Brotli compression.

Using CLI to check Brotli support, implies at least some knowledge of working with the Terminal app. So you can use your browser method instead.

Via browser

  • Launch Chrome browser and navigate to your website
  • Right-click anywhere on the opened page and choose “Inspect”.
  • Developer tools sidebar will open.
  • Click on “Network” in the developer tools sidebar, then “Doc”. This tells Chrome to log only requests to the main document.
  • Now reload the page, and expand the log entry which was created by clicking it.
  • Scroll down to “Response Headers” and find “Content-Encoding” header. The value of “br” means that the response was encoded via Brotli.
Plesk with Brotli
Plesk with Brotli

Troubleshooting

Enabling module

If running plesk sbin nginx_modules_ctl --enable brotli yields error:

START nginx_modules_ctl –enable brotli
exit status 1

There are 2 common reasons for this.

First, NGINX may be currently disabled in Plesk. Ensure that NGINX is enabled in the first place:

plesk sbin nginxmng -e

The other reason is misplacing the directive for loading the Plesk NGINX modules. In the file /etc/nginx/nginx.conf, ensure that the following line is located outside any context and not commented:

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

The meaning of “outside any context” is that the directive outside of any curly braces { ... }. It should be simply at the top of the configuration file.

There’s more

NGINX modules for Plesk allow both performance and security.
For example, check out secure NGINX configuration for WordPress in Plesk.

  1. tiagobahi

    Guys… You are amazing… The brotli module works correctly and it has full compatible with Plesk.

    Reply
  2. David

    Do you think this would work with Ubuntu as well?

    Reply
  3. Mike

    Hm, 30$ per month just to have the brotli extension? Absurd…

    Reply
    • Danila Vershinin

      Mike,

      The current pricing is $30 per first month and $10 for each following month.

      There is currently only the Brotli NGINX module that is highly compatible with Plesk.
      Other NGINX modules in our collection are not yet built for NGINX compatibility.

      But the repository subscription is not just about NGINX modules. You get access to the vast array of packages in the repository, including drop-in libraries that will improve your server performance.
      See faster Zlib by Intel/Cloudflare, MozJPEG encoding library,
      just for a couple of examples. You simply install those to make your server faster/better, with zero configuration.

      Of course, there’s far beyond that, you can see the list of all packages available on the repository page (table with repoview links).

      Reply
    • Danila Vershinin

      We’ve pushed several additional NGINX modules for Plesk. For example application, check secure WordPress configuration.

      Reply
  4. cliqerio

    Where do I add ‘pagespeed HttpCacheCompressionLevel 0;’?
    Also how do I check that brotli has been installed successfully and sites are using it?

    Reply
    • Danila Vershinin

      The pagespeed HttpCacheCompressionLevel 0; can be added at the top of http { } configuration section in /etc/nginx/nginx.conf.
      Depending on where you have placed directives for PageSpeed enablement, you might have to place it there instead.

      Added section to this post titled “Verify Brotli compression works”, the easiest way to check if it works is simply checking headers in Chrome.
      Alternatively, use KeyCDN tools Brotli test or our performance test which has Brotli as one of the checks.

      Reply

Leave a Reply

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

%d bloggers like this: