Site icon GetPageSpeed

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

NGINX with Brotli

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 the Better Brotli NGINX module for Plesk. Let’s go through some quick steps on bringing Brotli compression to Plesk.

Notes about Plesk own Brotli module for NGINX

For months, the GetPageSpeed repository has been the only source of the NGINX Brotli module for the Plesk’s own platform.
In late January 2021, Plesk shipped the Brotli module within its sw-nginx package.
The way it was done pretty much sucks for production due to several reasons:

To deal with all this mess, you can instead use our Plesk compatible NGINX Brotli module – The better Brotli NGINX module for Plesk.

Pre-requisites

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

Step 3. Disable Plesk Brotli module and Enable Better Brotli module

sudo plesk bin nginx -d brotli
sudo plesk sbin nginx_modules_ctl --enable better-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;. This is needed only if you have enabled the PageSpeed module:

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

Plesk with Brotli

Troubleshooting

Enabling module

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

START nginx_modules_ctl –enable better-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. There are more than 50 Plesk-compatible NGINX modules available through our repository.

Also, be sure to check out secure NGINX configuration for WordPress in Plesk which leverages some of those modules.

Exit mobile version