# How to use brotli compression instead of gzip

**URL:** <https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903>\
**Category:** Virtualmin\
**Created:** [February 10, 2024, 9:39pm UTC](https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903 "2024-02-10T21:39:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierrot](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@Pierrot](https://forum.virtualmin.com/u/Pierrot)\
**Post date:** [February 10, 2024, 9:39pm UTC](https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903/1 "2024-02-10T21:39:22Z")

</div>

| SYSTEM INFORMATION | |
| --- | --- |
| OS type and version | Debian 11 |
| Webmin version | 2.105 |
| Virtualmin version | 7.9.0 |

I have been trying for the last 3 hours to activate brotli compression on https for some virtualhost.  
1/ I did enable the brotli module in Webmin-\>Servers-\>Apache-\>Global Configuration-\>Apache modules, rebooted Apache.  
2/ brotli seems to be enabled looking at phpinfo()  
3/ then I added the following code to the virtualhost config both http/https:

```auto
<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml
    BrotliCompressionQuality 4
</IfModule>

```

4/ rebooted Apache again

Of course I made many more tests and attempts, always rebooting Apache, I also tried to add

```auto
Header set Accept-Encoding br,gzip,deflate
Header set Content-Encoding br
Header set Vary Accept-Encoding

```

which broke Apache (the 2nd line in fact broke Apache), but whatever I change, when I look at http headers for my page I see:

```auto
content-encoding gzip
Accept-Encoding gzip, deflate, br

```

which is confirmed by tests at [https://www.giftofspeed.com/](https://www.giftofspeed.com/) …  
I read a lot, googled a lot, looked at almost each and every config files for Apache to no avail, even tried to suppress the deflate module (which I don’t seem to be able to do), I’m still on gzip, not brotli … what am I missing ?  
Thanks for any tip that could put me on the right path …  
Pierre.

---

<div class="post-metadata">

**Author:** ![stefan1959](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@stefan1959](https://forum.virtualmin.com/u/stefan1959)\
**Post date:** [February 11, 2024, 12:44am UTC](https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903/2 "2024-02-11T00:44:32Z")

</div>

They make it sound easy

> **[Enable Brotli Compression for your Apache server in less than 5 minutes](https://www.brotli.pro/enable-brotli/servers/apache/)**
>
> Learn how you can enable Brotli compression for your Apache web server in a couple of minutes!

I don’t think these doc are for rocky like OS as I don’t have the a2enmod command and apache2  
I don’t have Webmin-\>Servers-\>Apache-\>Global Configuration-\>Apache modules that i can see.  
It do have a config file

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/f/f356d608711838cc845f377ae6a0e9c46ccffaee.png)

P.S. I added the code into one of the virtualservers and it worked (the site for testing you gave dosn’t work for me, found another and show great compression)

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/8/81714d53c3aaa1424534d31c2b07eea39220ae52.png)

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/a/a4004fa11048427714e05915f1ea3e5d8df2bbd7.png)

Improved page speed at [https://pagespeed.web.dev](https://pagespeed.web.dev)

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/d/decae27111e97bb8674aeab9a3e0feffd48300f0.png)

---

<div class="post-metadata">

**Author:** ![Pierrot](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@Pierrot](https://forum.virtualmin.com/u/Pierrot)\
**Post date:** [February 11, 2024, 9:56pm UTC](https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903/3 "2024-02-11T21:56:31Z")

</div>

Hello,  
That’s exactly the website I used to setup brotli, but still, tests on my website shows that I’m still using gzip.  
I made some more tests with different testing sites and it seems that my server is properly setup for both, I found 2 or 3 testing sites that do test both methods and they are telling me brotli is available and functionning, but still, the default method still seems to be gzip. For example [Brotli Test - Verify Brotli Compression Support | KeyCDN Tools](https://tools.keycdn.com/brotli-test) states that “Brotli compression is supported.”.

I think it might be a consequence of:

```auto
Accept-Encoding gzip, deflate, br

```

Which shows gzip as being the first method used … and this is the real header as seen when doing a webpage inspection (network, headers), so as of now, I think I did setup brotli properly but I would have to amend that order to have brotli as the preferred method.  
I looked everywhere in all the Apache config files, I cannot find that line anywhere … I would like to make it

```auto
Accept-Encoding br, gzip, deflate

```

That’s my current thinking at this time … well … I also tried adding

```auto
    Header add Accept-Encoding: br

```

to the virtual host config file, to the htaccess … the web inspector still gives me the same result, gzip is used.  
Pierre.

---

<div class="post-metadata">

**Author:** ![stefan1959](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@stefan1959](https://forum.virtualmin.com/u/stefan1959)\
**Post date:** [February 11, 2024, 10:09pm UTC](https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903/4 "2024-02-11T22:09:40Z")

</div>

remove gzip from that line, what happens?

---

<div class="post-metadata">

**Author:** ![Pierrot](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@Pierrot](https://forum.virtualmin.com/u/Pierrot)\
**Post date:** [February 12, 2024, 3:34pm UTC](https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903/5 "2024-02-12T15:34:31Z")

</div>

Well of course that’s the main purpose of my question … finding that line !

But, in the mean time I did more tests and I was able to get it to work.  
When looking at /etc/apache2/mods-available and /etc/apache2/mods-enabled I was seeing a brotli.load but no brotli.conf … I manually added brotli.conf with

```auto
<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml
    BrotliCompressionQuality 4
</IfModule>

```

and it started to work right away ! I don’t know if this is the right way to do it, well the .load and .conf are ok, what I don’t know is the reason why I had to do this manually … I don’t recall having to do this for other Apache modules added through Virtualmin.  
Pierre.

---

<div class="post-metadata">

**Author:** ![stefan1959](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@stefan1959](https://forum.virtualmin.com/u/stefan1959)\
**Post date:** [February 12, 2024, 9:53pm UTC](https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903/6 "2024-02-12T21:53:23Z")

</div>

All I did was add here, Rocky9 had brotli already configured.

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/d/d74538acd7703f6f34e6b4227fcbfab7c05face8.png)

---

<div class="post-metadata">

**Author:** ![system](https://cdn.forum.virtualmin.com/uploads/default/original/2X/c/cd96d761e326db4b2bef94886a639109bd7a8e76.svg) [@system](https://forum.virtualmin.com/u/system)\
**Post date:** [April 12, 2024, 9:53pm UTC](https://forum.virtualmin.com/t/how-to-use-brotli-compression-instead-of-gzip/124903/7 "2024-04-12T21:53:38Z")

</div>

Closed on April 12, 2024, 9:53pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
