Modify 'README.install-brotli' and add script 'mkbrotli.sh'.

This commit is contained in:
2022-04-02 02:52:45 +02:00
parent 2f2fcc6e18
commit 51da8fd016
2 changed files with 585 additions and 32 deletions

View File

@ -2,14 +2,15 @@
# Build dynamic Nginx module Brotli
# ==========
# Download ngx_brotli
#
cd /usr/local/src
git clone https://github.com/google/ngx_brotli.git
backup_date="$(date +%Y-%m-%d-%H%M)"
# download (clone) also submodules
builddir=/usr/local/src/nginx
mkdir -p /usr/local/src/nginx
cd "${builddir}"
# Install needed development packages if not yet installed in the system
#
git submodule update --init --recursive
apt -y install git libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev
# Find installed version of nginx
@ -18,55 +19,101 @@ git submodule update --init --recursive
#
# output like:
#
# nginx version: nginx/1.14.2
# Download nginx version 1.14.2
# nginx version: nginx/1.18.0
#
cd /usr/local/src/nginx
wget https://nginx.org/download/nginx-1.14.2.tar.gz
# For automated detection of currently installed NGINX version (not to be used
# for auto-updating, see hooks in post), use:
#
ngver=$(nginx -v 2>&1 | grep -o '[0-9\.]*')
# Get configure parameters of installed NGINX. Not needed if NGINX was configured '--with-compat'.
# Uncomment one of the lines below if the script sucessfully builds modules but NGINX throws
# a "not binary compatible" error.
confparams=$(nginx -V 2>&1 | grep -o -- '--prefix='.* | sed -e 's/ --add-dynamic-module=[^[:space:]]*//g')
[[ -z "${confparams}" ]] && confparams=$(nginx -V 2>&1 | grep -o -- '--[^with]'.* \
| sed -e 's/ --add-dynamic-module=[^[:space:]]*//g')
[[ -z "${confparams}" ]] && confparams=$(nginx -V 2>&1 | grep -- '--' | sed "s/.*' //" \
| sed -e 's/ --add-dynamic-module=[^[:space:]]*//g')
[[ -z "${confparams}" ]] && confparams=$(nginx -V 2>&1 | grep -o -- "--prefix='.*'$" \
| sed -e 's/ --add-dynamic-module=[^[:space:]]*//g')
# To automatically select NGINX modules directory:
#
[ -d /usr/share/nginx/modules ] && moddir=/usr/share/nginx/modules
[ -d $(nginx -V 2>&1 | grep -o 'prefix=[^ ]*' | sed 's/prefix=//')/modules ] && moddir="$(nginx -V 2>&1 | grep -o 'prefix=[^ ]*' | sed 's/prefix=//')/modules"
[ -d $(nginx -V 2>&1 | grep -o 'modules-path=[^ ]*' | sed 's/modules-path=//') ] && moddir="$(nginx -V 2>&1 | grep -o 'modules-path=[^ ]*' | sed 's/modules-path=//')"
[ "${moddir}" ] || { echo '!! missing modules directory, exiting...'; exit 1; }
# ---
# Download and unpack NGINX
# ---
[ -d "nginx-${ngver}" ] && mv "nginx-${ngver}" "nginx-${ngver}.${backup_date}"
wget https://nginx.org/download/nginx-${ngver}.tar.gz
# Umpack nginx souce code archive
gunzip < nginx-1.14.2.tar.gz | tar -xf -
gunzip < nginx-${ngver}.tar.gz | tar -xf -
cd nginx-1.14.2/
# Remove Downloadwed archive
rm nginx-${ngver}.tar.gz
# Configure nginx including dynamic brotli module
#
# From output of 'nginx -V' keep configure arguments,
# ---
# Download, initialize, and make Brotli dynamic modules
# ---
cd /usr/local/src
[ -d "ngx_brotli" ] && mv ngx_brotli ngx_brotli.${backup_date}
git clone https://github.com/google/ngx_brotli.git
# remove *all* flaggs like
cd ngx_brotli
# download (clone) also submodules
#
# --add-dynamic-module=<path-to-module>
#
# add
#
# --add-dynamic-module=/usr/local/src/ngx_brotli
#
./configure --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-tBUzFN/nginx-1.14.2=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_secure_link_module --with-http_sub_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --add-dynamic-module=/usr/local/src/ngx_brotli
#git submodule update --init --recursive
git submodule update --init
cd /usr/local/src/nginx/nginx-${ngver}
if [[ -z "${confparams}" ]] ; then
nice -n 19 ionice -c 3 ./configure --with-compat --add-dynamic-module=/usr/local/src/ngx_brotli
else
nice -n 19 ionice -c 3 ./configure --add-dynamic-module=/usr/local/src/ngx_brotli ${confparams}
fi
# Build modules
#
make modules
nice -n 19 ionice -c 3 make modules
# Add and load the dynamic brotli modules to nginx service
# Replace Brotli in modules directory
#
mkdir -p /etc/nginx/modules
[ -f "${moddir}/ngx_http_brotli_filter_module.so" ] && mv "${moddir}/ngx_http_brotli_filter_module.so" "${moddir}/ngx_http_brotli_filter_module.${backup_date}"
cp -a "/usr/local/src/nginx/nginx-${ngver}/objs/ngx_http_brotli_filter_module.so" \
"${moddir}/ngx_http_brotli_filter_module.so"
cp -a /usr/local/src/nginx/nginx-1.14.2/objs/ngx_http_brotli_filter_module.so /etc/nginx/modules/
cp -a /usr/local/src/nginx/nginx-1.14.2/objs/ngx_http_brotli_static_module.so /etc/nginx/modules/
[ -f "${moddir}/ngx_http_brotli_static_module.so" ] && mv "${moddir}/ngx_http_brotli_static_module.so" "${moddir}/ngx_http_brotli_static_module.so.${backup_date}"
cp -a "/usr/local/src/nginx/nginx-${ngver}/objs//ngx_http_brotli_static_module.so" \
"${moddir}/ngx_http_brotli_static_module.so"
# cp objs/*.so "${moddir}/"
chmod 644 "${moddir}/ngx_http_brotli_filter_module.so"
chmod 644 "${moddir}/ngx_http_brotli_static_module.so"
# Create load_module statements for the two brotli modules
#
cat <<EOF > /etc/nginx/modules-available/http-brotli-filter-module.conf
load_module /etc/nginx/modules/ngx_http_brotli_filter_module.so;
load_module ${moddir}/ngx_http_brotli_filter_module.so;
EOF
cat <<EOF > /etc/nginx/modules-available/http-brotli-static-module.conf
load_module /etc/nginx/modules/ngx_http_brotli_static_module.so;
load_module ${moddir}/ngx_http_brotli_static_module.so;
EOF
@ -75,6 +122,22 @@ EOF
ln -s ../modules-available/http-brotli-filter-module.conf /etc/nginx/modules-enabled/60-http-brotli-filter-module.conf
ln -s ../modules-available/http-brotli-static-module.conf /etc/nginx/modules-enabled/60-http-brotli-static-module.conf
# Configure Brotli
#
cat <<EOF > /etc/nginx/conf.d/http-brotli.conf
##
# Brotli Settings
##
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types text/xml image/svg+xml application/x-font-ttf image/vnd.microsoft.icon application/x-font-opentype application/json font/eot application/vnd.ms-fontobject application/javascript font/otf application/xml application/xhtml+xml text/javascript application/x-javascript text/plain application/x-font-truetype application/xml+rss image/x-icon font/opentype text/css image/x-win-bitmap;
# brotli_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
EOF
# Verify if all is fine
#
nginx -t