salnz
October 24, 2021, 4:20am
1
To enable Brotli in Apache2 is very simple
Step 1 - Install
apt-get install brotli
Step 2 - edit your custom template file .tpl and .stpl files / copy and edit new so kept after update.
/usr/local/hestia/data/templates/web/apache2/
add something like the below (depending on what extension you want to compress with Brotli
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>
under the last and save
</IfModule>
Enable in Apache2
a2enmod brotli
then
systemctl restart apache2
You can test if it worked here
Brotli Test - Verify Brotli Compression Support | KeyCDN Tools
or check heqaders
HTTP Header Checker - Check HTTP Response Headers With curl | KeyCDN Tools
You will get something like below
HTTP/2
200
server: nginx
date: Sun, 24 Oct 2021 04:11:37 GMT
content-type: text/html; charset=utf-8
content-length: 1005
last-modified: Sun, 24 Oct 2021 01:54:31 GMT
cache-control: max-age=86400, proxy-revalidate
expires: Mon, 25 Oct 2021 04:11:37 GMT
vary: Accept-Encoding,User-Agent
content-encoding: br
strict-transport-security: max-age=15768000;
accept-ranges: bytes
As always try at your own risk. This was tested on a fresh Deb 10 install
1 Like
I have a simple solution to add brotli to your apache server wide configuration without templates.
add
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>
to a file named brotli.conf in /etc/apache2/mods-enabled
I prefer the Apache2 solution to the Nginx solution because if something goes wrong with the Brotli module of apache, it will not crash the web server. The broli module of Apache2 is a default package of the Linux distro. So, it is already tested to work with your version of Apache 2. Anyways, if it does not work, it will not crash thanks to the ifmodule tag.
1 Like
trouble
September 1, 2024, 8:35am
4
The package libnginx-mod-http-brotli-filter is provided by Nginx since v.1.24.0-1
trouble
September 1, 2024, 8:36am
5
So, I added the following in nginx.conf
include /etc/nginx/modules-enabled/50-mod-http-brotli-filter.conf;
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types application/atom+xml application/javascript application/json application/vnd.api+json application/rss+xml
application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xm
Is Nginx serving static Brotli-compressed files now? Or still serving from Apache?