2015-09-17 19:09:29 -07:00
|
|
|
#!/usr/bin/env bash
|
2019-01-07 01:04:17 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $DOKKU_TRACE ]] && set -x
|
2015-09-17 19:09:29 -07:00
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
|
source "$PLUGIN_AVAILABLE_PATH/certs/functions"
|
|
|
|
|
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
2018-12-30 08:33:53 -05:00
|
|
|
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions"
|
2015-09-18 15:46:46 -07:00
|
|
|
|
2020-04-01 12:21:52 -04:00
|
|
|
fn-nginx-log-root() {
|
|
|
|
|
declare desc="get the nginx log root"
|
|
|
|
|
local NGINX_LOG_ROOT="/var/log/nginx"
|
|
|
|
|
fn-nginx-vhosts-uses-openresty && NGINX_LOG_ROOT="/var/log/openresty"
|
|
|
|
|
echo "$NGINX_LOG_ROOT"
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-30 21:59:36 -08:00
|
|
|
fn-nginx-access-log-format() {
|
|
|
|
|
declare desc="get the configured access log format"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "access-log-format" ""
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 12:21:52 -04:00
|
|
|
fn-nginx-access-log-path() {
|
|
|
|
|
declare desc="get the configured access log path"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
local NGINX_LOG_ROOT="$(fn-nginx-log-root)"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "access-log-path" "${NGINX_LOG_ROOT}/${APP}-access.log"
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-19 00:38:11 +09:30
|
|
|
fn-nginx-proxy-buffer-size() {
|
|
|
|
|
declare desc="get the configured proxy buffer size"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "proxy-buffer-size" "$(fn-get-pagesize)"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn-nginx-proxy-buffering() {
|
|
|
|
|
declare desc="get the configured proxy buffering"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "proxy-buffering" "on"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn-nginx-proxy-buffers() {
|
|
|
|
|
declare desc="get the configured proxy buffers"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "proxy-buffers" "8 $(fn-get-pagesize)"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn-nginx-proxy-busy-buffers-size() {
|
|
|
|
|
declare desc="get the configured proxy busy buffers size"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "proxy-busy-buffers-size" "$(($(fn-get-pagesize) * 2))"
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 19:08:15 -04:00
|
|
|
fn-nginx-proxy-read-timeout() {
|
|
|
|
|
declare desc="get the configured proxy read timeout"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "proxy-read-timeout" "60s"
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 11:27:22 -05:00
|
|
|
fn-nginx-client-max-body-size() {
|
|
|
|
|
declare desc="get the configured client max body size"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "client-max-body-size" ""
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 12:21:52 -04:00
|
|
|
fn-nginx-error-log-path() {
|
|
|
|
|
declare desc="get the configured access log path"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
local NGINX_LOG_ROOT="$(fn-nginx-log-root)"
|
|
|
|
|
|
|
|
|
|
fn-plugin-property-get-default "nginx" "$APP" "error-log-path" "${NGINX_LOG_ROOT}/${APP}-error.log"
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-18 19:46:47 +02:00
|
|
|
get_nginx_location() {
|
|
|
|
|
declare desc="check that nginx is at the expected location and return it"
|
2019-09-16 03:05:35 -04:00
|
|
|
fn-nginx-vhosts-nginx-location
|
2017-09-18 19:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-17 19:09:29 -07:00
|
|
|
validate_nginx() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="validate entire nginx config"
|
2018-12-30 08:33:53 -05:00
|
|
|
declare APP="${1:-}" FLAG="${2:-}"
|
|
|
|
|
local NGINX_LOCATION EXIT_CODE
|
2017-09-19 19:14:48 +02:00
|
|
|
NGINX_LOCATION=$(get_nginx_location)
|
2017-09-18 21:09:03 +02:00
|
|
|
if [[ -z "$NGINX_LOCATION" ]]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
exit 1
|
2017-09-18 19:46:47 +02:00
|
|
|
fi
|
|
|
|
|
|
2018-12-30 08:33:53 -05:00
|
|
|
if [[ "$APP" == "--clean" ]]; then
|
|
|
|
|
APP=""
|
|
|
|
|
FLAG="--clean"
|
|
|
|
|
fi
|
|
|
|
|
|
2015-09-17 19:09:29 -07:00
|
|
|
set +e
|
2019-01-07 01:04:17 -05:00
|
|
|
sudo "$NGINX_LOCATION" -t >/dev/null 2>&1
|
2018-12-30 08:33:53 -05:00
|
|
|
EXIT_CODE=$?
|
2015-09-17 19:09:29 -07:00
|
|
|
set -e
|
2018-12-30 08:33:53 -05:00
|
|
|
if [[ "$EXIT_CODE" -eq "0" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -n "$APP" ]]; then
|
2020-12-29 02:46:18 -05:00
|
|
|
verify_app_name "$APP"
|
2018-12-30 08:33:53 -05:00
|
|
|
nginx_vhosts_validate_single_func "$APP" "$FLAG"
|
|
|
|
|
else
|
2022-05-15 15:47:13 -04:00
|
|
|
for app in $(dokku_apps "false"); do
|
2018-12-30 08:33:53 -05:00
|
|
|
nginx_vhosts_validate_single_func "$app" "$FLAG"
|
2016-06-14 17:36:26 -07:00
|
|
|
done
|
2015-09-17 19:09:29 -07:00
|
|
|
fi
|
2018-12-30 08:33:53 -05:00
|
|
|
|
|
|
|
|
set +e
|
2019-01-07 01:04:17 -05:00
|
|
|
sudo "$NGINX_LOCATION" -t >/dev/null 2>&1
|
2018-12-30 08:33:53 -05:00
|
|
|
EXIT_CODE=$?
|
|
|
|
|
set -e
|
|
|
|
|
if [[ "$EXIT_CODE" -eq "0" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sudo "$NGINX_LOCATION" -t
|
|
|
|
|
exit $?
|
2015-09-17 19:09:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restart_nginx() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="restart nginx for given distros"
|
2021-12-31 00:48:47 -05:00
|
|
|
local PROXY_ENABLED="$(plugn trigger proxy-is-enabled "$APP")"
|
|
|
|
|
local PROXY_TYPE="$(plugn trigger proxy-type "$APP")"
|
2021-12-30 22:56:47 -05:00
|
|
|
if [[ "$PROXY_ENABLED" == "true" ]] && [[ "$PROXY_TYPE" == "nginx" ]]; then
|
2021-12-31 00:48:47 -05:00
|
|
|
fn-nginx-vhosts-nginx-init-cmd "reload"
|
2021-12-30 22:49:57 -05:00
|
|
|
fi
|
2015-09-17 19:09:29 -07:00
|
|
|
}
|
|
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
nginx_logs() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="display app nginx logs"
|
2019-09-16 03:05:35 -04:00
|
|
|
declare NGINX_LOGS_TYPE="${1#nginx:}" APP="$2"
|
|
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
local NGINX_LOGS_TYPE=${NGINX_LOGS_TYPE%-logs}
|
2020-04-01 12:21:52 -04:00
|
|
|
local NGINX_LOGS_PATH="$("fn-nginx-${NGINX_LOGS_TYPE}-log-path" "$APP")"
|
|
|
|
|
|
|
|
|
|
if [[ "$NGINX_LOGS_PATH" == "off" ]] || [[ "$NGINX_LOGS_PATH" == "/dev/null" ]]; then
|
|
|
|
|
dokku_log_fail "$NGINX_LOGS_TYPE logs are disabled for this app"
|
|
|
|
|
fi
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
if [[ $3 == "-t" ]]; then
|
2016-03-02 10:50:09 -08:00
|
|
|
local NGINX_LOGS_ARGS="-F"
|
2016-02-14 18:43:40 -08:00
|
|
|
else
|
2016-03-02 10:50:09 -08:00
|
|
|
local NGINX_LOGS_ARGS="-n 20"
|
2016-02-14 18:43:40 -08:00
|
|
|
fi
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
tail "$NGINX_LOGS_ARGS" "$NGINX_LOGS_PATH"
|
|
|
|
|
}
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
configure_nginx_ports() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="configure nginx listening ports"
|
2019-01-07 01:04:17 -05:00
|
|
|
local APP=$1
|
2016-02-22 10:16:57 -08:00
|
|
|
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
2017-07-03 10:59:07 +09:30
|
|
|
local DOKKU_PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT)
|
|
|
|
|
local DOKKU_PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT)
|
2016-06-14 17:36:26 -07:00
|
|
|
local DOKKU_PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP)
|
2020-05-06 00:16:51 -04:00
|
|
|
local IS_APP_VHOST_ENABLED=true
|
2016-06-15 16:22:45 -07:00
|
|
|
local UPSTREAM_PORT="5000"
|
2021-08-06 17:48:39 -04:00
|
|
|
plugn trigger domains-vhost-enabled "$APP" 2>/dev/null || IS_APP_VHOST_ENABLED=false
|
2016-02-14 18:43:40 -08:00
|
|
|
|
2017-07-03 10:59:07 +09:30
|
|
|
if [[ -z "$DOKKU_PROXY_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then
|
2016-06-14 17:36:26 -07:00
|
|
|
if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then
|
2021-09-05 00:36:58 -04:00
|
|
|
dokku_log_info1 "No proxy port set, setting to random open high port"
|
2017-07-03 11:07:07 +09:30
|
|
|
local PROXY_PORT=$(get_available_port)
|
2016-06-14 17:36:26 -07:00
|
|
|
else
|
2019-11-26 12:30:51 +01:00
|
|
|
local PROXY_PORT=$(config_get --global DOKKU_PROXY_PORT)
|
|
|
|
|
PROXY_PORT=${PROXY_PORT:=80}
|
2016-06-14 17:36:26 -07:00
|
|
|
fi
|
2019-03-12 21:08:47 -04:00
|
|
|
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_PORT="$PROXY_PORT"
|
2016-06-14 17:36:26 -07:00
|
|
|
fi
|
2017-07-03 10:59:07 +09:30
|
|
|
if [[ -z "$DOKKU_PROXY_SSL_PORT" ]]; then
|
2017-02-05 13:39:49 -05:00
|
|
|
if (is_ssl_enabled "$APP"); then
|
2019-11-26 12:30:51 +01:00
|
|
|
local PROXY_SSL_PORT=$(config_get --global DOKKU_PROXY_SSL_PORT)
|
|
|
|
|
PROXY_SSL_PORT=${PROXY_SSL_PORT:=443}
|
2017-01-30 03:04:02 -05:00
|
|
|
if [[ -z "$RAW_TCP_PORTS" ]] && [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then
|
2021-09-05 00:36:58 -04:00
|
|
|
dokku_log_info1 "No proxy ssl port set, setting to random open high port"
|
2017-07-03 11:07:07 +09:30
|
|
|
PROXY_SSL_PORT=$(get_available_port)
|
2015-09-17 19:09:29 -07:00
|
|
|
fi
|
2019-03-12 21:08:47 -04:00
|
|
|
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_SSL_PORT="$PROXY_SSL_PORT"
|
2016-06-17 15:25:09 -07:00
|
|
|
fi
|
2016-02-14 18:43:40 -08:00
|
|
|
fi
|
2016-06-14 17:36:26 -07:00
|
|
|
if [[ -z "$DOKKU_PROXY_PORT_MAP" ]]; then
|
|
|
|
|
if [[ -n "$RAW_TCP_PORTS" ]]; then
|
|
|
|
|
local RAW_TCP_PORT
|
|
|
|
|
for RAW_TCP_PORT in $RAW_TCP_PORTS; do
|
|
|
|
|
local PROXY_PORT_MAP+=" http:${RAW_TCP_PORT}:${RAW_TCP_PORT} "
|
|
|
|
|
done
|
2016-02-14 18:43:40 -08:00
|
|
|
else
|
2017-07-03 11:07:07 +09:30
|
|
|
local PROXY_PORT=${PROXY_PORT:-$DOKKU_PROXY_PORT}
|
|
|
|
|
local PROXY_SSL_PORT=${PROXY_SSL_PORT:-$DOKKU_PROXY_SSL_PORT}
|
2019-01-07 01:04:17 -05:00
|
|
|
[[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]] && local UPSTREAM_PORT="$(<"$DOKKU_ROOT/$APP/PORT.web.1")"
|
2017-07-03 11:07:07 +09:30
|
|
|
if [[ -n "$PROXY_PORT" ]] && [[ -n "$PROXY_SSL_PORT" ]]; then
|
|
|
|
|
local PROXY_PORT_MAP+=" http:${PROXY_PORT}:$UPSTREAM_PORT https:${PROXY_SSL_PORT}:$UPSTREAM_PORT "
|
|
|
|
|
elif [[ -n "$PROXY_PORT" ]]; then
|
|
|
|
|
local PROXY_PORT_MAP+=" http:${PROXY_PORT}:$UPSTREAM_PORT "
|
2016-06-14 17:36:26 -07:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [[ -n "$PROXY_PORT_MAP" ]]; then
|
|
|
|
|
local PROXY_PORT_MAP="$(echo "$PROXY_PORT_MAP" | xargs)"
|
|
|
|
|
local PROXY_PORT_MAP+=" $(merge_dedupe_list "$(remove_val_from_list "$PORT_MAP" "$DOKKU_PROXY_PORT_MAP" " ")" " ") "
|
2019-03-12 21:08:47 -04:00
|
|
|
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_PORT_MAP="$PROXY_PORT_MAP"
|
2016-02-14 18:43:40 -08:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
validate_ssl_domains() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="check configured domains against SSL cert contents and show warning if mismatched"
|
2019-01-07 01:04:17 -05:00
|
|
|
local APP=$1
|
2020-05-06 00:16:51 -04:00
|
|
|
local VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
|
2016-02-22 10:16:57 -08:00
|
|
|
local SSL_HOSTNAME=$(get_ssl_hostnames "$APP")
|
2016-02-14 18:43:40 -08:00
|
|
|
local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g')
|
|
|
|
|
|
2020-02-17 05:59:52 -05:00
|
|
|
if ! (grep -q -E "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" &>/dev/null); then
|
2016-02-14 18:43:40 -08:00
|
|
|
dokku_log_info1 "No matching configured domains for $APP found in SSL certificate. Your app will show as insecure in a browser if accessed via SSL"
|
|
|
|
|
dokku_log_info1 "Please add appropriate domains via the dokku domains command"
|
|
|
|
|
[[ -n "$NONSSL_VHOSTS" ]] && dokku_log_info1 "Configured domains for app:"
|
2016-06-14 17:36:26 -07:00
|
|
|
local domain
|
2019-01-07 01:04:17 -05:00
|
|
|
for domain in $(echo "$NONSSL_VHOSTS" | xargs); do
|
2016-02-14 18:43:40 -08:00
|
|
|
dokku_log_info2 "$domain"
|
|
|
|
|
done
|
|
|
|
|
[[ -n "$SSL_HOSTNAME" ]] && dokku_log_info1 "Domains found in SSL certificate:"
|
2016-02-22 10:16:57 -08:00
|
|
|
for domain in $(echo "$SSL_HOSTNAME" | xargs); do
|
2016-02-14 18:43:40 -08:00
|
|
|
dokku_log_info2 "$domain"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
}
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
get_custom_nginx_template() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="attempts to copy custom nginx template from app image"
|
2019-01-07 01:04:17 -05:00
|
|
|
local APP="$1"
|
2019-08-01 19:32:04 -04:00
|
|
|
local DESTINATION_FILE="$2"
|
2016-02-22 10:16:57 -08:00
|
|
|
local IMAGE_TAG="$(get_running_image_tag "$APP")"
|
2016-07-29 12:49:29 -04:00
|
|
|
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
|
2016-02-14 18:43:40 -08:00
|
|
|
local NGINX_TEMPLATE_NAME="nginx.conf.sigil"
|
2020-09-04 11:29:23 -04:00
|
|
|
local DISABLE_CUSTOM_CONFIG="$(fn-plugin-property-get-default "nginx" "$APP" "disable-custom-config" "false")"
|
|
|
|
|
|
|
|
|
|
if [[ "$DISABLE_CUSTOM_CONFIG" == "true" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2019-08-01 19:32:04 -04:00
|
|
|
copy_from_image "$IMAGE" "$NGINX_TEMPLATE_NAME" "$DESTINATION_FILE" 2>/dev/null || true
|
2016-02-14 18:43:40 -08:00
|
|
|
}
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2019-10-14 11:47:35 -04:00
|
|
|
is_tls13_available() {
|
2019-10-31 17:07:13 +09:00
|
|
|
declare desc="detects whether the installed nginx version has TLSv1.3 support"
|
2019-10-14 11:47:35 -04:00
|
|
|
local NGINX_VERSION="$1"
|
|
|
|
|
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
|
|
|
|
local HAS_SUPPORT=false
|
|
|
|
|
|
|
|
|
|
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
|
|
|
|
|
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
|
|
|
|
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
|
|
|
|
if [[ "$MAJOR_VERSION" -ge "2" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
elif [[ "$MAJOR_VERSION" -eq "1" ]] && [[ "$MINOR_VERSION" -ge "13" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo $HAS_SUPPORT
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 00:25:46 -04:00
|
|
|
is_spdy_enabled() {
|
2016-11-21 19:33:50 -07:00
|
|
|
declare desc="detects whether the installed nginx version has spdy support"
|
2016-06-13 00:25:46 -04:00
|
|
|
local NGINX_VERSION="$1"
|
|
|
|
|
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
|
|
|
|
local HAS_SUPPORT=true
|
|
|
|
|
|
|
|
|
|
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
|
|
|
|
|
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
|
|
|
|
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
|
|
|
|
if [[ "$MAJOR_VERSION" -ge "2" ]]; then
|
|
|
|
|
HAS_SUPPORT=false
|
|
|
|
|
elif [[ "$MAJOR_VERSION" -eq "1" ]]; then
|
|
|
|
|
if [[ "$MINOR_VERSION" -ge "10" ]]; then
|
|
|
|
|
HAS_SUPPORT=false
|
|
|
|
|
elif [[ "$MINOR_VERSION" -ge "9" ]] && [[ "$PATCH_VERSION" -ge "5" ]]; then
|
|
|
|
|
HAS_SUPPORT=false
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo $HAS_SUPPORT
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-01 12:58:16 -04:00
|
|
|
is_http2_push_enabled() {
|
|
|
|
|
declare desc="detects whether the installed nginx version has http2 push support"
|
|
|
|
|
local NGINX_VERSION="$1"
|
|
|
|
|
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
|
|
|
|
local HAS_SUPPORT=false
|
|
|
|
|
|
|
|
|
|
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
|
|
|
|
|
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
|
|
|
|
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
|
|
|
|
if [[ "$MAJOR_VERSION" -ge "2" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
elif [[ "$MAJOR_VERSION" -eq "1" ]]; then
|
|
|
|
|
if [[ "$MINOR_VERSION" -eq "13" ]] && [[ "$PATCH_VERSION" -ge "9" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
elif [[ "$MINOR_VERSION" -ge "14" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo $HAS_SUPPORT
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 19:33:50 -07:00
|
|
|
is_http2_enabled() {
|
|
|
|
|
declare desc="detects whether the installed nginx version has http2 support"
|
|
|
|
|
local NGINX_VERSION="$1"
|
|
|
|
|
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
|
|
|
|
local HAS_SUPPORT=false
|
|
|
|
|
|
|
|
|
|
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
|
|
|
|
|
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
|
|
|
|
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
|
|
|
|
if [[ "$MAJOR_VERSION" -ge "2" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
elif [[ "$MAJOR_VERSION" -eq "1" ]]; then
|
|
|
|
|
if [[ "$MINOR_VERSION" -eq "11" ]] && [[ "$PATCH_VERSION" -ge "5" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
elif [[ "$MINOR_VERSION" -ge "12" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo $HAS_SUPPORT
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 22:59:11 +02:00
|
|
|
is_grpc_enabled() {
|
|
|
|
|
declare desc="detects whether the installed nginx version has grpc support"
|
|
|
|
|
local NGINX_VERSION="$1"
|
|
|
|
|
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
|
|
|
|
local HAS_SUPPORT=false
|
|
|
|
|
|
|
|
|
|
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
|
|
|
|
|
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
|
|
|
|
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
|
|
|
|
if [[ "$MAJOR_VERSION" -ge "2" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
elif [[ "$MAJOR_VERSION" -eq "1" ]]; then
|
|
|
|
|
if [[ "$MINOR_VERSION" -eq "13" ]] && [[ "$PATCH_VERSION" -ge "10" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
elif [[ "$MINOR_VERSION" -ge "14" ]]; then
|
|
|
|
|
HAS_SUPPORT=true
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo $HAS_SUPPORT
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
nginx_build_config() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="build nginx config to proxy app containers using sigil"
|
2020-09-06 13:57:35 -04:00
|
|
|
declare APP="$1" DOKKU_APP_LISTEN_PORT="$2" DOKKU_APP_LISTEN_IP="$3"
|
2019-01-07 01:04:17 -05:00
|
|
|
local VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
|
2020-07-16 05:40:56 +01:00
|
|
|
local APP_URLS_PATH="$DOKKU_ROOT/$APP/URLS"
|
2016-02-14 18:43:40 -08:00
|
|
|
local NGINX_TEMPLATE_NAME="nginx.conf.sigil"
|
2020-09-06 13:57:35 -04:00
|
|
|
local NGINX_TEMPLATE="$PLUGIN_AVAILABLE_PATH/nginx-vhosts/templates/$NGINX_TEMPLATE_NAME"
|
2019-01-07 01:04:17 -05:00
|
|
|
local SCHEME=http
|
|
|
|
|
local NGINX_TEMPLATE_SOURCE="built-in"
|
|
|
|
|
local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls"
|
2016-02-22 10:16:57 -08:00
|
|
|
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
2017-07-22 15:38:32 -06:00
|
|
|
local DOKKU_APP_LISTENERS
|
2016-02-14 18:43:40 -08:00
|
|
|
|
2020-09-06 13:57:35 -04:00
|
|
|
CUSTOM_NGINX_TEMPLATE="$(plugn trigger nginx-app-template-source "$APP" "app-config")"
|
|
|
|
|
if [[ -n "$CUSTOM_NGINX_TEMPLATE" ]]; then
|
|
|
|
|
NGINX_TEMPLATE="$CUSTOM_NGINX_TEMPLATE"
|
|
|
|
|
fi
|
|
|
|
|
|
2020-05-06 00:16:51 -04:00
|
|
|
local IS_APP_VHOST_ENABLED=true
|
2021-08-06 17:48:39 -04:00
|
|
|
plugn trigger domains-vhost-enabled "$APP" 2>/dev/null || IS_APP_VHOST_ENABLED=false
|
2016-02-14 18:43:40 -08:00
|
|
|
|
2020-02-22 06:35:30 -05:00
|
|
|
if [[ "$(plugn trigger proxy-is-enabled "$APP")" == "true" ]]; then
|
2016-02-14 18:43:40 -08:00
|
|
|
if [[ -z "$DOKKU_APP_LISTEN_PORT" ]] && [[ -z "$DOKKU_APP_LISTEN_IP" ]]; then
|
2020-03-11 12:34:29 -04:00
|
|
|
DOKKU_APP_LISTENERS="$(plugn trigger network-get-listeners "$APP" "web" | xargs)"
|
2016-02-14 18:43:40 -08:00
|
|
|
elif [[ -n "$DOKKU_APP_LISTEN_PORT" ]] && [[ -n "$DOKKU_APP_LISTEN_IP" ]]; then
|
|
|
|
|
local PASSED_LISTEN_IP_PORT=true
|
2015-09-17 19:09:29 -07:00
|
|
|
fi
|
|
|
|
|
|
2016-06-14 17:36:26 -07:00
|
|
|
# setup nginx listen ports
|
|
|
|
|
configure_nginx_ports "$APP"
|
2017-07-03 11:07:07 +09:30
|
|
|
local PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT)
|
|
|
|
|
local PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT)
|
2016-06-14 17:36:26 -07:00
|
|
|
local PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP)
|
|
|
|
|
|
|
|
|
|
local PORT_MAP
|
|
|
|
|
for PORT_MAP in $PROXY_PORT_MAP; do
|
2019-01-07 01:04:17 -05:00
|
|
|
local PROXY_UPSTREAM_PORT="$(awk -F ':' '{ print $3 }' <<<"$PORT_MAP")"
|
2016-06-14 17:36:26 -07:00
|
|
|
if [[ "$(is_val_in_list "$PROXY_UPSTREAM_PORT" "$PROXY_UPSTREAM_PORTS" " ")" == "false" ]]; then
|
|
|
|
|
local PROXY_UPSTREAM_PORTS+="$PROXY_UPSTREAM_PORT "
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
local PROXY_UPSTREAM_PORTS="$(echo "$PROXY_UPSTREAM_PORTS" | xargs)"
|
|
|
|
|
|
2020-02-01 21:16:39 -05:00
|
|
|
local SSL_INUSE=
|
2020-05-06 00:16:51 -04:00
|
|
|
local NONSSL_VHOSTS=$(plugn trigger domains-list "$APP")
|
2016-02-22 10:16:57 -08:00
|
|
|
local NOSSL_SERVER_NAME=$(echo "$NONSSL_VHOSTS" | xargs)
|
2016-02-14 18:43:40 -08:00
|
|
|
if is_ssl_enabled "$APP"; then
|
2019-01-07 01:04:17 -05:00
|
|
|
local SSL_INUSE=true
|
|
|
|
|
local SCHEME=https
|
2016-02-14 18:43:40 -08:00
|
|
|
validate_ssl_domains "$APP"
|
2016-02-22 10:16:57 -08:00
|
|
|
local SSL_HOSTNAME=$(get_ssl_hostnames "$APP")
|
2016-02-14 18:43:40 -08:00
|
|
|
local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g')
|
|
|
|
|
|
|
|
|
|
if [[ "$IS_APP_VHOST_ENABLED" == "true" ]]; then
|
2020-02-17 05:59:52 -05:00
|
|
|
local SSL_VHOSTS=$(grep -E "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" || true)
|
2016-02-14 18:43:40 -08:00
|
|
|
else
|
2021-08-06 17:48:39 -04:00
|
|
|
local SSL_VHOSTS=$(<"$DOKKU_ROOT/VHOST")
|
2016-02-14 18:43:40 -08:00
|
|
|
fi
|
2016-12-04 18:49:25 -08:00
|
|
|
local SSL_SERVER_NAME
|
|
|
|
|
local host
|
|
|
|
|
for host in $SSL_VHOSTS; do
|
|
|
|
|
# SSL_SERVER_NAME should only contain items not in NOSSL_SERVER_NAME
|
|
|
|
|
if [[ ! $NOSSL_SERVER_NAME =~ (^|[[:space:]])$host($|[[:space:]]) ]]; then
|
|
|
|
|
SSL_SERVER_NAME="${host}${SSL_SERVER_NAME:+ $SSL_SERVER_NAME}"
|
|
|
|
|
fi
|
|
|
|
|
done
|
2015-09-17 19:09:29 -07:00
|
|
|
fi
|
2016-06-13 00:25:46 -04:00
|
|
|
|
2019-10-14 11:47:35 -04:00
|
|
|
local NGINX_LOCATION NGINX_VERSION SPDY_SUPPORTED TLS13_SUPPORTED HTTP2_SUPPORTED HTTP2_PUSH_SUPPORTED GRPC_SUPPORTED
|
2017-09-19 19:14:48 +02:00
|
|
|
NGINX_LOCATION=$(get_nginx_location)
|
2017-09-18 21:09:03 +02:00
|
|
|
if [[ -z "$NGINX_LOCATION" ]]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
exit 1
|
2017-09-18 19:46:47 +02:00
|
|
|
fi
|
2017-09-19 19:14:48 +02:00
|
|
|
NGINX_VERSION="$("$NGINX_LOCATION" -v 2>&1 | cut -d'/' -f 2)"
|
|
|
|
|
SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")"
|
2019-10-14 11:47:35 -04:00
|
|
|
TLS13_SUPPORTED="$(is_tls13_available "$NGINX_VERSION")"
|
2017-09-19 19:14:48 +02:00
|
|
|
HTTP2_SUPPORTED="$(is_http2_enabled "$NGINX_VERSION")"
|
2018-05-01 12:58:16 -04:00
|
|
|
HTTP2_PUSH_SUPPORTED="$(is_http2_push_enabled "$NGINX_VERSION")"
|
2019-08-21 22:59:11 +02:00
|
|
|
GRPC_SUPPORTED="$(is_grpc_enabled "$NGINX_VERSION")"
|
2016-06-13 00:25:46 -04:00
|
|
|
|
2017-01-21 21:17:52 -05:00
|
|
|
PROXY_PORT_MAP=$(echo "$PROXY_PORT_MAP" | xargs) # trailing spaces mess up default template
|
|
|
|
|
|
2020-04-01 12:21:52 -04:00
|
|
|
local NGINX_LOG_ROOT="$(fn-nginx-log-root)"
|
2020-11-30 21:59:36 -08:00
|
|
|
local NGINX_ACCESS_LOG_FORMAT="$(fn-nginx-access-log-format "$APP")"
|
2020-04-01 12:21:52 -04:00
|
|
|
local NGINX_ACCESS_LOG_PATH="$(fn-nginx-access-log-path "$APP")"
|
|
|
|
|
local NGINX_ERROR_LOG_PATH="$(fn-nginx-error-log-path "$APP")"
|
2021-01-13 11:27:22 -05:00
|
|
|
local CLIENT_MAX_BODY_SIZE="$(fn-nginx-client-max-body-size "$APP")"
|
2020-07-01 19:08:15 -04:00
|
|
|
local PROXY_READ_TIMEOUT="$(fn-nginx-proxy-read-timeout "$APP")"
|
2020-09-19 00:38:11 +09:30
|
|
|
local PROXY_BUFFER_SIZE="$(fn-nginx-proxy-buffer-size "$APP")"
|
|
|
|
|
local PROXY_BUFFERING="$(fn-nginx-proxy-buffering "$APP")"
|
|
|
|
|
local PROXY_BUFFERS="$(fn-nginx-proxy-buffers "$APP")"
|
|
|
|
|
local PROXY_BUSY_BUFFERS_SIZE="$(fn-nginx-proxy-busy-buffers-size "$APP")"
|
2019-09-16 03:05:35 -04:00
|
|
|
|
2018-12-27 05:28:58 -05:00
|
|
|
if [[ -z "$DOKKU_APP_LISTENERS" ]]; then
|
|
|
|
|
dokku_log_warn_quiet "No web listeners specified for $APP"
|
|
|
|
|
elif (is_deployed "$APP"); then
|
2021-08-06 01:29:25 -04:00
|
|
|
if [[ "$(plugn trigger network-get-static-listeners "$APP" "web")" == "" ]]; then
|
|
|
|
|
local IMAGE_TAG=$(get_running_image_tag "$APP")
|
|
|
|
|
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG" 2>/dev/null)
|
|
|
|
|
if ! verify_image "$IMAGE" 2>/dev/null; then
|
|
|
|
|
dokku_log_fail "Missing image for app"
|
|
|
|
|
fi
|
2019-10-07 12:18:54 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local NGINX_BUILD_CONFIG_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
|
|
|
|
local NGINX_CONF=$(mktemp --tmpdir="${NGINX_BUILD_CONFIG_TMP_WORK_DIR}" "nginx.conf.XXXXXX")
|
|
|
|
|
local CUSTOM_NGINX_TEMPLATE="$NGINX_BUILD_CONFIG_TMP_WORK_DIR/$NGINX_TEMPLATE_NAME"
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
trap "rm -rf '$NGINX_CONF' '$NGINX_BUILD_CONFIG_TMP_WORK_DIR' >/dev/null" RETURN INT TERM EXIT
|
|
|
|
|
|
|
|
|
|
get_custom_nginx_template "$APP" "$CUSTOM_NGINX_TEMPLATE" 2>/dev/null
|
|
|
|
|
if [[ -f "$CUSTOM_NGINX_TEMPLATE" ]]; then
|
|
|
|
|
dokku_log_info1 'Overriding default nginx.conf with detected nginx.conf.sigil'
|
|
|
|
|
local NGINX_TEMPLATE="$CUSTOM_NGINX_TEMPLATE"
|
|
|
|
|
local NGINX_TEMPLATE_SOURCE="app-supplied"
|
|
|
|
|
fi
|
|
|
|
|
|
2019-12-19 02:23:50 -05:00
|
|
|
local NGINX_BIND_ADDRESS_IP4="$(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv4" "")"
|
|
|
|
|
local NGINX_BIND_ADDRESS_IP6="$(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv6" "::")"
|
|
|
|
|
[[ -z "$NGINX_BIND_ADDRESS_IP6" ]] && NGINX_BIND_ADDRESS_IP6="::"
|
|
|
|
|
|
2021-01-19 21:40:47 +01:00
|
|
|
local PROXY_X_FORWARDED_FOR="$(fn-plugin-property-get-default "nginx" "$APP" "x-forwarded-for-value" "\$remote_addr")"
|
|
|
|
|
local PROXY_X_FORWARDED_PORT="$(fn-plugin-property-get-default "nginx" "$APP" "x-forwarded-port-value" "\$server_port")"
|
|
|
|
|
local PROXY_X_FORWARDED_PROTO="$(fn-plugin-property-get-default "nginx" "$APP" "x-forwarded-proto-value" "\$scheme")"
|
2021-02-20 00:02:33 -05:00
|
|
|
local PROXY_X_FORWARDED_SSL="$(fn-plugin-property-get-default "nginx" "$APP" "x-forwarded-ssl" "")"
|
2021-01-18 21:09:00 +01:00
|
|
|
|
2019-10-07 12:18:54 -04:00
|
|
|
eval "$(config_export app "$APP")"
|
|
|
|
|
local SIGIL_PARAMS=(-f "$NGINX_TEMPLATE" APP="$APP" DOKKU_ROOT="$DOKKU_ROOT"
|
|
|
|
|
NOSSL_SERVER_NAME="$NOSSL_SERVER_NAME"
|
2020-03-11 12:34:29 -04:00
|
|
|
# Deprecated: Remove this after a few versions
|
2019-10-07 12:18:54 -04:00
|
|
|
DOKKU_APP_LISTENERS="$DOKKU_APP_LISTENERS"
|
|
|
|
|
DOKKU_LIB_ROOT="$DOKKU_LIB_ROOT"
|
|
|
|
|
PASSED_LISTEN_IP_PORT="$PASSED_LISTEN_IP_PORT"
|
|
|
|
|
SPDY_SUPPORTED="$SPDY_SUPPORTED"
|
2019-10-14 11:47:35 -04:00
|
|
|
TLS13_SUPPORTED="$TLS13_SUPPORTED"
|
2019-10-07 12:18:54 -04:00
|
|
|
HTTP2_SUPPORTED="$HTTP2_SUPPORTED"
|
2019-10-07 18:55:29 -05:00
|
|
|
NGINX_LOG_ROOT="$NGINX_LOG_ROOT"
|
2020-11-30 21:59:36 -08:00
|
|
|
NGINX_ACCESS_LOG_FORMAT="$NGINX_ACCESS_LOG_FORMAT"
|
2020-04-01 12:21:52 -04:00
|
|
|
NGINX_ACCESS_LOG_PATH="$NGINX_ACCESS_LOG_PATH"
|
|
|
|
|
NGINX_ERROR_LOG_PATH="$NGINX_ERROR_LOG_PATH"
|
2019-12-19 02:23:50 -05:00
|
|
|
NGINX_BIND_ADDRESS_IP4="$NGINX_BIND_ADDRESS_IP4"
|
|
|
|
|
NGINX_BIND_ADDRESS_IP6="$NGINX_BIND_ADDRESS_IP6"
|
2019-10-07 12:18:54 -04:00
|
|
|
HTTP2_PUSH_SUPPORTED="$HTTP2_PUSH_SUPPORTED"
|
2019-10-07 18:55:29 -05:00
|
|
|
GRPC_SUPPORTED="$GRPC_SUPPORTED"
|
2019-10-07 12:18:54 -04:00
|
|
|
DOKKU_APP_LISTEN_PORT="$DOKKU_APP_LISTEN_PORT" DOKKU_APP_LISTEN_IP="$DOKKU_APP_LISTEN_IP"
|
|
|
|
|
APP_SSL_PATH="$APP_SSL_PATH" SSL_INUSE="$SSL_INUSE" SSL_SERVER_NAME="$SSL_SERVER_NAME"
|
2021-01-13 11:27:22 -05:00
|
|
|
CLIENT_MAX_BODY_SIZE="$CLIENT_MAX_BODY_SIZE"
|
2020-07-01 19:08:15 -04:00
|
|
|
PROXY_READ_TIMEOUT="$PROXY_READ_TIMEOUT"
|
2020-09-19 00:38:11 +09:30
|
|
|
PROXY_BUFFER_SIZE="$PROXY_BUFFER_SIZE"
|
|
|
|
|
PROXY_BUFFERING="$PROXY_BUFFERING"
|
|
|
|
|
PROXY_BUFFERS="$PROXY_BUFFERS"
|
|
|
|
|
PROXY_BUSY_BUFFERS_SIZE="$PROXY_BUSY_BUFFERS_SIZE"
|
2020-03-11 12:34:29 -04:00
|
|
|
# Deprecated: Remove this after a few versions
|
2019-10-07 12:18:54 -04:00
|
|
|
NGINX_PORT="$PROXY_PORT" NGINX_SSL_PORT="$PROXY_SSL_PORT"
|
|
|
|
|
PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS"
|
2021-01-18 21:09:00 +01:00
|
|
|
PROXY_PORT_MAP="$PROXY_PORT_MAP" PROXY_UPSTREAM_PORTS="$PROXY_UPSTREAM_PORTS"
|
2021-01-19 21:40:47 +01:00
|
|
|
PROXY_X_FORWARDED_FOR="$PROXY_X_FORWARDED_FOR"
|
|
|
|
|
PROXY_X_FORWARDED_PORT="$PROXY_X_FORWARDED_PORT"
|
2021-02-20 00:02:33 -05:00
|
|
|
PROXY_X_FORWARDED_PROTO="$PROXY_X_FORWARDED_PROTO"
|
|
|
|
|
PROXY_X_FORWARDED_SSL="$PROXY_X_FORWARDED_SSL")
|
2019-10-07 12:18:54 -04:00
|
|
|
|
2020-03-11 12:34:29 -04:00
|
|
|
while read -r line || [[ -n "$line" ]]; do
|
|
|
|
|
PROC_TYPE=${line%%=*}
|
|
|
|
|
LISTENERS="$(plugn trigger network-get-listeners "$APP" "$PROC_TYPE" | xargs)"
|
|
|
|
|
UPP_PROC_TYPE="${PROC_TYPE^^}"
|
|
|
|
|
UPP_PROC_TYPE="${UPP_PROC_TYPE//-/_}"
|
2020-07-04 00:08:44 +02:00
|
|
|
SIGIL_PARAMS+=("DOKKU_APP_${UPP_PROC_TYPE}_LISTENERS=$LISTENERS")
|
2021-08-01 01:53:46 -04:00
|
|
|
done < <(plugn trigger ps-current-scale "$APP")
|
2020-03-11 12:34:29 -04:00
|
|
|
|
|
|
|
|
if grep DOKKU_APP_LISTENERS "$NGINX_TEMPLATE"; then
|
|
|
|
|
dokku_log_warn "Deprecated: Usage of DOKKU_APP_LISTENERS within nginx.conf.sigil templates is deprecated in favor of DOKKU_APP_WEB_LISTENERS"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if grep NGINX_SSL_PORT "$NGINX_TEMPLATE"; then
|
|
|
|
|
dokku_log_warn "Deprecated: Usage of NGINX_SSL_PORT within nginx.conf.sigil templates is deprecated in favor of PROXY_SSL_PORT"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if grep NGINX_PORT "$NGINX_TEMPLATE"; then
|
|
|
|
|
dokku_log_warn "Deprecated: Usage of NGINX_PORT within nginx.conf.sigil templates is deprecated in favor of PROXY_PORT"
|
|
|
|
|
fi
|
|
|
|
|
|
2018-12-27 05:28:58 -05:00
|
|
|
# execute sigil template processing
|
2019-01-07 01:04:17 -05:00
|
|
|
xargs -i echo "-----> Configuring {}...(using $NGINX_TEMPLATE_SOURCE template)" <<<"$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)"
|
|
|
|
|
sigil "${SIGIL_PARAMS[@]}" | cat -s >"$NGINX_CONF"
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2016-01-07 07:43:08 -08:00
|
|
|
dokku_log_info1 "Creating $SCHEME nginx.conf"
|
2016-02-22 10:16:57 -08:00
|
|
|
mv "$NGINX_CONF" "$DOKKU_ROOT/$APP/nginx.conf"
|
2015-09-17 19:09:29 -07:00
|
|
|
|
2020-02-01 21:16:39 -05:00
|
|
|
fn-nginx-vhosts-manage-hsts "$APP" "$SSL_INUSE"
|
|
|
|
|
|
2016-02-22 10:16:57 -08:00
|
|
|
plugn trigger nginx-pre-reload "$APP" "$DOKKU_APP_LISTEN_PORT" "$DOKKU_APP_LISTEN_IP"
|
2015-09-17 19:09:29 -07:00
|
|
|
|
|
|
|
|
dokku_log_verbose "Reloading nginx"
|
2019-09-16 03:05:35 -04:00
|
|
|
validate_nginx && restart_nginx >/dev/null
|
2015-09-17 19:09:29 -07:00
|
|
|
fi
|
|
|
|
|
|
2016-02-14 18:43:40 -08:00
|
|
|
if ([[ -n "$NONSSL_VHOSTS" ]] || [[ -n "$SSL_VHOSTS" ]]) && [[ "$IS_APP_VHOST_ENABLED" == "true" ]]; then
|
2020-07-16 05:40:56 +01:00
|
|
|
echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" >"$APP_URLS_PATH"
|
|
|
|
|
xargs -i echo "$SCHEME://{}" <<<"$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)" >>"$APP_URLS_PATH"
|
2015-09-17 19:09:29 -07:00
|
|
|
fi
|
|
|
|
|
else
|
2017-09-03 05:30:47 -04:00
|
|
|
# note because this clause is long. if the proxy is disabled:
|
2021-09-05 00:36:58 -04:00
|
|
|
dokku_log_info1 "Nginx support is disabled for app ($APP)"
|
2015-09-17 19:09:29 -07:00
|
|
|
if [[ -f "$DOKKU_ROOT/$APP/nginx.conf" ]]; then
|
2021-09-05 00:36:58 -04:00
|
|
|
dokku_log_info1 "Deleting nginx.conf"
|
2015-09-17 19:09:29 -07:00
|
|
|
rm "$DOKKU_ROOT/$APP/nginx.conf"
|
|
|
|
|
|
2016-07-17 18:16:45 -04:00
|
|
|
if (is_deployed "$APP"); then
|
2021-09-05 00:36:58 -04:00
|
|
|
dokku_log_info1 "Reloading nginx after nginx.conf deletion"
|
2019-09-16 03:05:35 -04:00
|
|
|
validate_nginx && restart_nginx >/dev/null
|
2015-09-17 19:09:29 -07:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|