Last active
October 27, 2020 08:12
-
-
Save majal/82aa3de30c163fc624a05eb02d72f12c to your computer and use it in GitHub Desktop.
Bash script for automating dynamic module creation and installation of Brotli on NGINX.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://www.majlovesreg.one/tag/code/ | |
# https://www.majlovesreg.one/adding-brotli-to-a-running-nginx-instance | |
# For custom NGINX version, use: | |
# ngver=1.14.2 | |
# For automated detection of installed NGINX, use: | |
ngver=$(nginx -v 2>&1 | grep -oP '(?<=/).*') | |
moddir=/usr/share/nginx/modules/ | |
# Install needed development packages if not yet installed in your system | |
# sudo apt -y install git libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev | |
# Download and unpack NGINX | |
wget https://nginx.org/download/nginx-${ngver}.tar.gz && tar zxf nginx-${ngver}.tar.gz && rm nginx-${ngver}.tar.gz | |
# Download, initialize, and make Brotli for NGINX | |
git clone https://github.com/eustas/ngx_brotli.git | |
cd ngx_brotli && git submodule update --init && cd ../nginx-${ngver} | |
./configure --with-compat --add-dynamic-module=../ngx_brotli | |
make modules | |
# Copy modules to you modules directory, i.e. /usr/share/nginx/modules/ | |
sudo cp objs/*.so ${moddir} | |
sudo chmod 644 ${moddir}ngx_http_brotli_filter_module.so | |
sudo chmod 644 ${moddir}ngx_http_brotli_static_module.so | |
# Start or reload NGINX | |
if [ $(nginx -t) ]; then systemctl is-active --quiet nginx && sudo systemctl --no-pager reload nginx || sudo systemctl --no-pager start nginx; fi | |
systemctl --no-pager status nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment