Skip to content

Commit 311272a

Browse files
author
Daniel Hansson
committed
add brotli script
Signed-off-by: Daniel Hansson <[email protected]>
1 parent 881ac2f commit 311272a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

addons/brotli-nginx.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# T&M Hansson IT AB © - 2024, https://www.hanssonit.se/
4+
# Copyright © 2024 Simon Lindner (https://github.com/szaimen)
5+
6+
# shellcheck disable=2034,2059
7+
true
8+
SCRIPT_NAME="Nginx Brotli"
9+
SCRIPT_EXPLAINER="Enables Brotli compression support for Nginx"
10+
# shellcheck source=lib.sh
11+
source /var/scripts/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/lib.sh)
12+
13+
# Check for errors + debug code and abort if something isn't right
14+
# 1 = ON
15+
# 0 = OFF
16+
DEBUG=0
17+
debug_mode
18+
19+
# Check if root
20+
root_check
21+
22+
# Replace old Nginx with new
23+
install_if_not ppa-purge
24+
add-apt-repository ppa:ondrej/nginx
25+
apt update -q4 && spinner_loading
26+
apt-get update nginx -y
27+
ppa-purge nginx/stable
28+
rm -f /etc/apt/sources.list.d/nginx*
29+
apt-get autoremove -y
30+
31+
# Enable Brotli
32+
install_of_not sponge
33+
install_if_not libnginx-mod-brotli
34+
{
35+
echo "# https://docs.nginx.com/nginx/admin-guide/dynamic-modules/brotli/"
36+
echo "load_module modules/ngx_http_brotli_filter_module.so; # for compressing responses on-the-fly"
37+
echo "load_module modules/ngx_http_brotli_static_module.so; # for serving pre-compressed files"
38+
} | cat - "$NGINX_CONF" | sponge "$NGINX_CONF"
39+
apt-get purge sponge -y
40+
41+
if nginx -t
42+
then
43+
systemctl restart nginx
44+
fi

0 commit comments

Comments
 (0)