nginx installed with homebrew from the core tap
git installed and all the software needed to build something from source
First of all, you need to get your currently installed nginx version simply by executing:
nginx -v
You should obtain something like this:
nginx version: nginx/1.17.10
The 1.17.10
is the version number that you must use to get the nginx source code you can create a VAR called nginx_version, and use this in further commands.
Create a new folder that will be further mentioned as "working folder", cd into it and:
curl https://nginx.org/download/nginx-${nginx_version}.tar.gz | tar -xz -C .
you should have a new folder called nginx-${nginx_version}
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli && git submodule update --init && cd -
You should be in you working folder with two folders: nginx-${nginx_version} and ngx_brotli
cd nginx-${nginx_version}
./configure --with-compat --add-dynamic-module=../ngx_brotli
this will build nginx with ngx_brotli module
make modules
this will generate the *.so files, ready to be placed under the modules folder of your local installed version of nginx.
At the time of writing, the version 1.17.10 installed with homebrew, doesn't set a specific modules path and in this case you have to create it under the prefix folder of your nginx.
Anyway, running this command will tell you if the modules-path has been specified at compile-time for your current nginx binary:
nginx -V &>/dev/stdout | sed 's/--/\
--/g' | grep 'modules-path=' | awk -F '=' '{print $NF}'
If this command doesn't output anything, you must create the modules folder under nginx prefix's folder. Running the following, you'll get the prefix folder of your installed nginx:
nginx -V &>/dev/stdout | sed 's/--/\
--/g' | grep 'prefix=' | awk -F '=' '{print $NF}'
In my case, I get /usr/local/Cellar/nginx/1.17.10
so:
mkdir /usr/local/Cellar/nginx/1.17.10/modules
if the previous return something like: mkdir: /usr/local/Cellar/nginx/1.17.10/modules: File exists
you have the modules folder already created, problably because another dynamic module has been already installed.
Now that you got the modules folder's path, you can copy the previously compiled *.so files
cp objs/*.so /usr/local/Cellar/nginx/1.17.10/modules
Having added the brotli modules under your modules path, the last remaining step is to load them in the top-level (“main”) context of the main nginx configuration file (nginx.conf), above the http block, with load_module directive:
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
http: {
...
}