Skip to content

Commit dc4492a

Browse files
authored
Resolve hestiacp#3684 Process "http2" directive for NGINX (hestiacp#3704)
* Process "http2" directive for NGINX * Update v-update-sys-ip
1 parent 3532b86 commit dc4492a

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

bin/v-add-sys-ip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ if [ -n "$WEB_SYSTEM" ]; then
145145
elif [ "$WEB_SYSTEM" = 'nginx' ]; then
146146
cp -f $HESTIA_INSTALL_DIR/nginx/unassigned.inc "$web_conf"
147147
sed -i 's/directIP/'$ip'/g' "$web_conf"
148+
process_http2_directive "$web_conf"
148149
fi
149150

150151
if [ "$WEB_SSL" = 'mod_ssl' ]; then
@@ -165,6 +166,8 @@ if [ -n "$PROXY_SYSTEM" ]; then
165166
-e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
166167
> /etc/$PROXY_SYSTEM/conf.d/$ip.conf
167168

169+
process_http2_directive "/etc/$PROXY_SYSTEM/conf.d/$ip.conf"
170+
168171
# mod_extract_forwarded
169172
fw_conf="/etc/$WEB_SYSTEM/conf.d/mod_extract_forwarded.conf"
170173
if [ -e "$fw_conf" ]; then

bin/v-update-sys-ip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ source /etc/hestiacp/hestia.conf
2020
source $HESTIA/func/main.sh
2121
# shellcheck source=/usr/local/hestia/func/ip.sh
2222
source $HESTIA/func/ip.sh
23+
# shellcheck source=/usr/local/hestia/func/domain.sh
24+
source $HESTIA/func/domain.sh
2325
# load config file
2426
source_conf "$HESTIA/conf/hestia.conf"
2527

@@ -93,10 +95,12 @@ if [ -n "$old_ip" ]; then
9395
# Updating WEB
9496
if [ -n "$WEB_SYSTEM" ]; then
9597
cd /etc/$WEB_SYSTEM/conf.d
98+
9699
if [ -e "$old_ip.conf" ]; then
97100
mv $old_ip.conf $new_ip.conf
98101
sed -i "s/$old_ip/$new_ip/g" $new_ip.conf
99102
fi
103+
100104
for user in $($BIN/v-list-sys-users plain); do
101105
sed -i "s/$old_ip/$new_ip/g" $HESTIA/data/users/$user/web.conf
102106
$BIN/v-rebuild-web-domains "$user" no
@@ -156,6 +160,8 @@ for ip in $ips; do
156160
prefixlen="$(ip -d -j addr show | jq --arg IP "$ip" -r '.[].addr_info[] | if .local == $IP then .prefixlen else empty end')"
157161
netmask="$(convert_cidr "$prefixlen")"
158162
$BIN/v-add-sys-ip "$ip" "$netmask" "$interface"
163+
elif [ -e "/etc/nginx/conf.d/$ip.conf" ]; then
164+
process_http2_directive "/etc/nginx/conf.d/$ip.conf"
159165
fi
160166
done
161167

func/domain.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ add_web_config() {
289289
-e "s|%ssl_ca%|$ssl_ca|g" \
290290
> $conf
291291

292+
process_http2_directive "$conf"
293+
292294
chown root:$user $conf
293295
chmod 640 $conf
294296

@@ -857,6 +859,8 @@ add_webmail_config() {
857859
-e "s|%ssl_ca%|$ssl_ca|g" \
858860
> $conf
859861

862+
process_http2_directive "$conf"
863+
860864
chown root:$user $conf
861865
chmod 640 $conf
862866

@@ -1018,3 +1022,35 @@ is_base_domain_owner() {
10181022
fi
10191023
done
10201024
}
1025+
1026+
#----------------------------------------------------------#
1027+
# Process "http2" directive for NGINX #
1028+
#----------------------------------------------------------#
1029+
1030+
process_http2_directive() {
1031+
if [ -e /etc/nginx/conf.d/http2-directive.conf ]; then
1032+
while IFS= read -r old_param; do
1033+
new_param="$(echo "$old_param" | sed 's/\shttp2//')"
1034+
sed -i "s/$old_param/$new_param/" "$1"
1035+
done < <(grep -E "listen.*(\bssl\b(\s|.+){1,}\bhttp2\b|\bhttp2\b(\s|.+){1,}\bssl\b).*;" "$1")
1036+
else
1037+
if version_ge "$(nginx -v 2>&1 | cut -d'/' -f2)" "1.25.1"; then
1038+
echo "http2 on;" > /etc/nginx/conf.d/http2-directive.conf
1039+
1040+
while IFS= read -r old_param; do
1041+
new_param="$(echo "$old_param" | sed 's/\shttp2//')"
1042+
sed -i "s/$old_param/$new_param/" "$1"
1043+
done < <(grep -E "listen.*(\bssl\b(\s|.+){1,}\bhttp2\b|\bhttp2\b(\s|.+){1,}\bssl\b).*;" "$1")
1044+
else
1045+
listen_ssl="$(grep -E "listen.*\s\bssl\b(?:\s)*.*;" "$1")"
1046+
listen_http2="$(grep -E "listen.*(\bssl\b(\s|.+){1,}\bhttp2\b|\bhttp2\b(\s|.+){1,}\bssl\b).*;" "$1")"
1047+
1048+
if [ -n "$listen_ssl" ] && [ -z "$listen_http2" ]; then
1049+
while IFS= read -r old_param; do
1050+
new_param="$(echo "$old_param" | sed 's/\sssl/ ssl http2/')"
1051+
sed -i "s/$old_param/$new_param/" "$1"
1052+
done < <(grep -E "listen.*\s\bssl\b(?:\s)*.*;" "$1")
1053+
fi
1054+
fi
1055+
fi
1056+
}

0 commit comments

Comments
 (0)