Enabling Brotli compression on Apache

CentOS Web Panel is deployed in Contact us to find out our latest offers!

The mod_brotli module provides the BROTLI_COMPRESS output filter that allows output from your server to be compressed using the brotli compression format before being sent to the client over the network. This module uses the Brotli library found at https://github.com/google/brotli.

Follow the installation procedure steps to install mod_brotli :-

Install Brotli on your server

yum install pcre-devel cmake -ycd usr/local/src
git clone https://github.com/google/brotli.git
cd brotli
git checkout v1.0
./configure-cmake
make && make install

Adding path for dependencies files:

grep "/usr/local/lib/" /etc/ld.so.conf || echo "/usr/local/lib/" >> /etc/ld.so.conf
ldconfig

Compile Apache with this flags from CWP Apache rebuild module :

--enable-brotli
--with-brotli=/usr

After Apache is rebuilded add this configs and create the config file :

touch /usr/local/apache/conf.d/brotli.conf

Now add this line to /usr/local/apache/conf.d/brotli.conf :

LoadModule brotli_module modules/mod_brotli.so

BrotliCompressionQuality 6

BrotliFilterNote Input brotli_input_info
BrotliFilterNote Output brotli_output_info
BrotliFilterNote Ratio brotli_ratio_info
LogFormat '"%r" %{brotli_output_info}n/%{brotli_input_info}n (%{brotli_ratio_info}n%%)' brotli
CustomLog "logs/brotli_log" brotli

#Don't compress content which is already compressed
SetEnvIfNoCase Request_URI 
.(gif|jpe?g|png|swf|woff|woff2) no-brotli dont-vary

#Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

After configuration restart Apache webserver :

service httpd restart

To enable brotli compression for your site add config to .htaccess :


AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript application/json application/x-font-ttf application/vnd.ms-fontobject image/x-icon

 

CentOS Web Panel is deployed in Contact us to find out our latest offers!

Comments are closed.

>
WhatsApp WhatsApp us