From 311272aefe34b70abeba0508ab59a5861401c22b Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 2 Oct 2024 21:43:36 +0200 Subject: [PATCH] add brotli script Signed-off-by: Daniel Hansson --- addons/brotli-nginx.sh | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 addons/brotli-nginx.sh diff --git a/addons/brotli-nginx.sh b/addons/brotli-nginx.sh new file mode 100644 index 0000000..5dbdd15 --- /dev/null +++ b/addons/brotli-nginx.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# T&M Hansson IT AB © - 2024, https://www.hanssonit.se/ +# Copyright © 2024 Simon Lindner (https://github.com/szaimen) + +# shellcheck disable=2034,2059 +true +SCRIPT_NAME="Nginx Brotli" +SCRIPT_EXPLAINER="Enables Brotli compression support for Nginx" +# shellcheck source=lib.sh +source /var/scripts/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/lib.sh) + +# Check for errors + debug code and abort if something isn't right +# 1 = ON +# 0 = OFF +DEBUG=0 +debug_mode + +# Check if root +root_check + +# Replace old Nginx with new +install_if_not ppa-purge +add-apt-repository ppa:ondrej/nginx +apt update -q4 && spinner_loading +apt-get update nginx -y +ppa-purge nginx/stable +rm -f /etc/apt/sources.list.d/nginx* +apt-get autoremove -y + +# Enable Brotli +install_of_not sponge +install_if_not libnginx-mod-brotli +{ +echo "# https://docs.nginx.com/nginx/admin-guide/dynamic-modules/brotli/" +echo "load_module modules/ngx_http_brotli_filter_module.so; # for compressing responses on-the-fly" +echo "load_module modules/ngx_http_brotli_static_module.so; # for serving pre-compressed files" +} | cat - "$NGINX_CONF" | sponge "$NGINX_CONF" +apt-get purge sponge -y + +if nginx -t +then + systemctl restart nginx +fi