Added proxy template for support proxy request from nginx to another service

This commit is contained in:
Alexey Berezhok
2024-10-07 23:21:17 +03:00
parent 9d93d56a05
commit 3225e8cbea
10 changed files with 206 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# info: add webdomain proxy support
# options: USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART]
# options: USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART] [PORT]
#
# example: v-add-web-domain-proxy admin example.com
#
@@ -19,6 +19,7 @@ default_extentions="jpg,jpeg,gif,png,webp,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls
exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
extentions=${4-$default_extentions}
restart="$5"
proxy_port_internal=${6-"0"}
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
@@ -36,7 +37,7 @@ source_conf "$HESTIA/conf/hestia.conf"
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART]'
check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART] [PORT]'
is_format_valid 'user' 'domain' 'extentions'
is_system_enabled "$PROXY_SYSTEM" 'PROXY_SYSTEM'
is_object_valid 'user' 'USER' "$user"
@@ -63,11 +64,12 @@ local_ip=$(get_real_ip "$IP")
# Preparing domain values for the template substitution
PROXY_EXT="$extentions"
add_web_config "$PROXY_SYSTEM" "$template.tpl"
PROXY_PORT_INTERNAL="$proxy_port_internal"
add_web_config "$PROXY_SYSTEM" "$template.tpl" "$PROXY_PORT_INTERNAL"
# Adding proxy for ssl
if [ "$SSL" = 'yes' ]; then
add_web_config "$PROXY_SYSTEM" "$template.stpl"
add_web_config "$PROXY_SYSTEM" "$template.stpl" "$PROXY_PORT_INTERNAL"
fi
#----------------------------------------------------------#
@@ -77,12 +79,14 @@ fi
# Update config
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$template"
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
[ -z "$PROXY_PORT_INTERNAL" ] && add_object_key 'web' 'DOMAIN' "$domain" 'PROXY_PORT_INTERNAL' 'PROXY'
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_PORT_INTERNAL' "$proxy_port_internal"
# Restarting web server
$BIN/v-restart-proxy "$restart"
check_result $? "Proxy restart failed" > /dev/null
$BIN/v-log-action "$user" "Info" "Web" "Proxy enabled (Domain: $domain)."
$BIN/v-log-action "$user" "Info" "Web" "Proxy enabled (Domain: $domain, Port: $proxy_port_internal)."
log_event "$OK" "$ARGUMENTS"
exit