Want to use brotli on aapanel? but don't know or there are lots of tutorials that seem like a waste of time? Relax, here I will give you a tutorial that will definitely work (if the Aapanel or Nginx version is not much different huh).

First of all, we have to know what brotli is, and what its uses are.

What is Brotli

Brotli is a data compression algorithm developed by Google. This algorithm is designed to compress data more efficiently than previous data compression algorithms, such as Gzip or Deflate. The goal is to reduce the size of data sent over the internet, which in turn can increase the speed and efficiency in the process of sending data over the network.

Some of Brotli's advantages include a higher compression rate, meaning that data can be compressed to a smaller size than other compression methods, and this can reduce bandwidth usage as well as the time required to download or transfer data. Brotli also supports text compression such as HTML, CSS, and JavaScript well, so it can be used to compress text files used in web development.

Brotli is commonly used in the context of modern web servers and web browsers to compress and decompress data when accessing websites. This helps in improving the performance and user experience while browsing the internet. Brotli has been well received by the web development community and is increasingly being used to optimize websites and web applications.

Uses of Brotli

Brotli has several main uses in the context of web and app development:

  1. Web Data Compression: One of the main uses of Brotli is to compress various types of data used in web development, such as HTML, CSS, JavaScript, and other text files. By compressing this data using Brotli, file sizes can be reduced significantly, which reduces the time required to download and load web pages. This allows websites to load faster, improve user experience, and reduce bandwidth usage.
  2. Browser Data Compression: Brotli is also used by modern web browsers to decompress data sent by web servers. When the browser receives data that has been compressed with Brotli, it can decompress the data to restore it to the original. This helps in saving bandwidth and allows the browser to load content faster.
  3. Application Data Compression: Apart from being used to compress web data, Brotli can also be used to compress data in other applications, such as games or software applications. This can help reduce storage usage and speed up data transfer between applications.
  4. Data Compression in Transfer Protocols: Brotli can be used in data transfer protocols such as HTTP to compress data sent between the server and the client. This helps reduce latency and the time required to load web pages or transfer data.
  5. Use in CDN (Content Delivery Network): Brotli is often used by CDN providers to compress and deliver web content to end users more efficiently. This helps in reducing server load, improving performance, and saving bandwidth.

Add brotli to nginx in AAPanel

After knowing what brotli is and its uses, you can follow the steps below to add the brotli module to nginx which will be installed on aapanel. Here I use a VPS with the Almalinux 9 operating system. Let's just follow this:

Install git

If you haven't installed git, then the installation will most likely fail. To find out whether git is installed, you can use the command: “git” in the terminal, if the git commands appear, then git is installed, if there is an error, then git is not installed. To install git, on the Almalinux, rockylinux operating systems you can use: “dnf install git”.

Add the module to the installation

The second is to add a module to the installation, you open the app store menu, search for NginX and click install. Then you will be presented with the options “Fast” and “Compiled“. You select the compiled one, then add the module as follows:

How to Add Brotli to NginX in AaPanel (Updated Dec 2023) - Screenshot 2023 10 08 030459

Fill in as follows:

Name: the name for this module, it can be whatever you want.

Parameters: parameters for compiling nginx as follows:

--add-module=/www/server/ngx_brotli

Prefix Script: script that will be run for this module. You fill it in as follows:

mkdir -p /www/server/ngx_brotli
git clone https://github.com/google/ngx_brotli.git /www/server/ngx_brotli
cd /www/server/ngx_brotli && git submodule update --init

After you have finished filling in everything, you click submit and you will be treated as shown:

How to Add Brotli to NginX in AaPanel (Updated Dec 2023) - Screenshot 2023 10 08 030512

You just click submit and wait until it's finished. If you're done, now let's add some configuration so that nginx can use brotli.

New Update!

Now you can't install brotli as static module (if you want, you have to edit the nginx installation script from aapanel) or follow this link for more info. Now you have to use it as a dynamic module.

So? how to do it?

Install brotli as dynamic module:

– Download latest ngx_brotli either using git or direct download the zip file.

– extract and configure like this:

//if you're not already have temp folder
mkdir /www/server/tempinstall

cd /www/server/tempinstall
git clone --recurse-submodules -j8 https://github.com/google/ngx_brotli
cd ngx_brotli/deps/brotli
mkdir out && cd out
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed ..
cmake --build . --config Release --target brotlienc
cd ../../../..

– Then open nginx installation folder (src). Use command below:

cd /www/server/nginx/src

– After that, use “nginx -V” to see your nginx “./configure” configuration. The result should looks like this (note: I'm using custom build, your config may different):

configure arguments: --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/build/lua-nginx-module --add-module=/www/server/nginx/src/ngx_cache_purge --with-openssl=/www/build/openssl --add-module=/www/build/ngx_brotli --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_v3_module --with-http_mp4_module --add-module=/www/server/nginx/src/ngx_http_substitutions_filter_module-master --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module

– Copy anything after “configure arguments:” and type this on the terminal:

$ cd nginx-1.x.x
#change /path/to/ngx_brotli with /www/server/tempinstall/ngx_brotli or whatever folder you put earlier.
$ ./configure <paste your nginx config here> --with-compat --add-dynamic-module=/path/to/ngx_brotli
$ make modules

– After the script is completed, open “/www/server/nginx/objs/” and fine ngx_http_brotli_filter_module.so and ngx_http_brotli_static_module.so file. Copy or move it to /www/server/nginx/module or leave it there.

– Then, you can add this line to your nginx.conf (nginx main config on aapanel) before the http block:

# change "your module folder" to where the file exist.
load_module <your module folder>/ngx_http_brotli_filter_module.so;
load_module <your module folder>/ngx_http_brotli_static_module.so;

it should looks like this:

How to Add Brotli to NginX in AaPanel (Updated Dec 2023) - gambar 5

Add the following code to the http block as follows:

http
{
#other nginx config...

brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types application/atom+xml application/javascript;

#other nginx config...
}

You can add mime types to brotli_types. Mime types are the types of files that will be compressed using brotli. You can add or delete unwanted files. I use the following files:

application/atom+xml application/javascript application/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+xmlimage/vnd.microsoft.icon image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;

Conclusion

Adding brotli to nginx in aapanel is actually easy, but sometimes we confuse ourselves too much. Also, there are many tutorials that are no longer running but are still being used and have not been updated.

Adding brotli can be done in just a few steps, as explained above.

About the Author

Dzul Qurnain

Suka nonton Anime, ngoding dan bagi-bagi tips kalau tahu.. Oh iya, suka baca ( tapi yang menarik menurutku aja)...

View All Articles