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 

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 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 🙂

Plesk with Brotli
Plesk with Brotli
  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
    • Danila Vershinin

      No, it will not work with Ubuntu.

      Reply
      • erdinckoc

        [root@server ~]# sudo nginx -t && sudo systemctl restart nginx
        nginx: [emerg] unknown directive “brotli” in /etc/nginx/conf.d/brotli.conf:1
        nginx: configuration file /etc/nginx/nginx.conf test failed

        Reply
        • Danila Vershinin

          You haven’t run steps 1 through 3. The module needs to be installed in order to function.

          Reply
  3. Bragi Austfjörð

    Could you please update this so I can install this on Plesk Centos 8. I got this error.

    [root@hq ~]# sudo yum install sw-nginx-module-nbr
    GetPageSpeed packages for Plesk on Enterprise Linux 8 – x86_64 276 B/s | 170 B 00:00
    Failed to download metadata for repo ‘getpagespeed-extras-plesk’
    Error: Failed to download metadata for repo ‘getpagespeed-extras-plesk’
    [root@hq ~]#

    Reply
    • Danila Vershinin

      Just added package for CentOS 8. Please run “yum clean all” to refresh repo metadata then try again.

      Reply
    • Bragi Austfjörð

      Yeah found out why, just needed to buy license lol.

      Reply
      • Bragi Austfjörð

        Is this the only NGINX plugin you have for plesk.

        Reply
        • Bragi Austfjörð

          Like Varnish

          Reply
          • Danila Vershinin

            All the software in the base repository is accessible on your subscription. Including Varnish and Varnish modules. (Varnish is not an NGINX plugin by the way, it’s a standalone software). For NGINX modules that are compatible with Plesk’s NGINX, there is indeed only Brotli so far. In theory you could replace Plesk’s NGINX with the NGINX from GetPageSpeed base repository (and then be able to install any of the to 50+ modules), but I’d better play safe so as not to break the Plesk. Any specific module you’re interested with to be built for Plesk?

Leave a Reply

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