|
|
|
|
@@ -54,10 +54,10 @@ nginx_logs() {
|
|
|
|
|
configure_nginx_ports() {
|
|
|
|
|
local desc="configure nginx listening ports"
|
|
|
|
|
local APP=$1; verify_app_name "$APP"
|
|
|
|
|
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports $APP)"
|
|
|
|
|
local DOKKU_NGINX_PORT=$(config_get $APP DOKKU_NGINX_PORT)
|
|
|
|
|
local DOKKU_NGINX_SSL_PORT=$(config_get $APP DOKKU_NGINX_SSL_PORT)
|
|
|
|
|
local IS_APP_VHOST_ENABLED="$(is_app_vhost_enabled $APP)"
|
|
|
|
|
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
|
|
|
|
local DOKKU_NGINX_PORT=$(config_get "$APP" DOKKU_NGINX_PORT)
|
|
|
|
|
local DOKKU_NGINX_SSL_PORT=$(config_get "$APP" DOKKU_NGINX_SSL_PORT)
|
|
|
|
|
local IS_APP_VHOST_ENABLED="$(is_app_vhost_enabled "$APP")"
|
|
|
|
|
|
|
|
|
|
if [[ -z "$DOKKU_NGINX_PORT" ]]; then
|
|
|
|
|
if [[ -z "$RAW_TCP_PORTS" ]]; then
|
|
|
|
|
@@ -69,37 +69,37 @@ configure_nginx_ports() {
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [[ -n "$NGINX_PORT" ]]; then
|
|
|
|
|
config_set --no-restart $APP DOKKU_NGINX_PORT="${NGINX_PORT}"
|
|
|
|
|
config_set --no-restart "$APP" DOKKU_NGINX_PORT="${NGINX_PORT}"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if (is_ssl_enabled $APP) && [[ -z "$DOKKU_NGINX_SSL_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then
|
|
|
|
|
if (is_ssl_enabled "$APP") && [[ -z "$DOKKU_NGINX_SSL_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then
|
|
|
|
|
if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then
|
|
|
|
|
dokku_log_info1 "no nginx ssl port set. setting to random open high port"
|
|
|
|
|
local NGINX_SSL_PORT=$(get_available_port)
|
|
|
|
|
else
|
|
|
|
|
local NGINX_SSL_PORT=443
|
|
|
|
|
fi
|
|
|
|
|
config_set --no-restart $APP DOKKU_NGINX_SSL_PORT=${NGINX_SSL_PORT}
|
|
|
|
|
config_set --no-restart "$APP" DOKKU_NGINX_SSL_PORT="${NGINX_SSL_PORT}"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validate_ssl_domains() {
|
|
|
|
|
local desc="check configured domains against SSL cert contents and show warning if mismatched"
|
|
|
|
|
local APP=$1; verify_app_name "$APP"
|
|
|
|
|
local SSL_HOSTNAME=$(get_ssl_hostnames $APP)
|
|
|
|
|
local SSL_HOSTNAME=$(get_ssl_hostnames "$APP")
|
|
|
|
|
local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g')
|
|
|
|
|
local domain
|
|
|
|
|
|
|
|
|
|
if ! (egrep -q "^${SSL_HOSTNAME_REGEX}$" $VHOST_PATH &> /dev/null); then
|
|
|
|
|
if ! (egrep -q "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" &> /dev/null); then
|
|
|
|
|
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:"
|
|
|
|
|
for domain in $(echo $NONSSL_VHOSTS| xargs); do
|
|
|
|
|
for domain in $(echo "$NONSSL_VHOSTS"| xargs); do
|
|
|
|
|
dokku_log_info2 "$domain"
|
|
|
|
|
done
|
|
|
|
|
[[ -n "$SSL_HOSTNAME" ]] && dokku_log_info1 "Domains found in SSL certificate:"
|
|
|
|
|
for domain in $(echo $SSL_HOSTNAME | xargs); do
|
|
|
|
|
for domain in $(echo "$SSL_HOSTNAME" | xargs); do
|
|
|
|
|
dokku_log_info2 "$domain"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
@@ -108,8 +108,8 @@ validate_ssl_domains() {
|
|
|
|
|
get_custom_nginx_template() {
|
|
|
|
|
local APP="$1"; verify_app_name "$APP"
|
|
|
|
|
local DESTINATION="$2"
|
|
|
|
|
local IMAGE_TAG="$(get_running_image_tag $APP)"
|
|
|
|
|
local IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
|
|
|
|
|
local IMAGE_TAG="$(get_running_image_tag "$APP")"
|
|
|
|
|
local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
|
|
|
|
|
local NGINX_TEMPLATE_NAME="nginx.conf.sigil"
|
|
|
|
|
|
|
|
|
|
copy_from_image "$IMAGE" "$NGINX_TEMPLATE_NAME" "$DESTINATION" 2>/dev/null || true
|
|
|
|
|
@@ -124,10 +124,10 @@ nginx_build_config() {
|
|
|
|
|
local DEFAULT_NGINX_TEMPLATE="$PLUGIN_AVAILABLE_PATH/nginx-vhosts/templates/$NGINX_TEMPLATE_NAME"
|
|
|
|
|
local NGINX_TEMPLATE="$DEFAULT_NGINX_TEMPLATE"; local SCHEME=http
|
|
|
|
|
local NGINX_TEMPLATE_SOURCE="built-in"; local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls"
|
|
|
|
|
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports $APP)"
|
|
|
|
|
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
|
|
|
|
|
|
|
|
|
local DOKKU_DISABLE_PROXY=$(config_get $APP DOKKU_DISABLE_PROXY)
|
|
|
|
|
local IS_APP_VHOST_ENABLED=$(is_app_vhost_enabled $APP)
|
|
|
|
|
local DOKKU_DISABLE_PROXY=$(config_get "$APP" DOKKU_DISABLE_PROXY)
|
|
|
|
|
local IS_APP_VHOST_ENABLED=$(is_app_vhost_enabled "$APP")
|
|
|
|
|
|
|
|
|
|
if [[ -z "$DOKKU_DISABLE_PROXY" ]]; then
|
|
|
|
|
if [[ -z "$DOKKU_APP_LISTEN_PORT" ]] && [[ -z "$DOKKU_APP_LISTEN_IP" ]]; then
|
|
|
|
|
@@ -135,25 +135,26 @@ nginx_build_config() {
|
|
|
|
|
local DOKKU_APP_IP_FILE
|
|
|
|
|
for DOKKU_APP_IP_FILE in $DOKKU_ROOT/$APP/IP.web.*; do
|
|
|
|
|
local DOKKU_APP_PORT_FILE="${DOKKU_APP_IP_FILE//IP/PORT}"
|
|
|
|
|
local DOKKU_APP_LISTENER_IP=$(< $DOKKU_APP_IP_FILE)
|
|
|
|
|
local DOKKU_APP_LISTENER_PORT=$(< $DOKKU_APP_PORT_FILE)
|
|
|
|
|
local DOKKU_APP_LISTENER_IP=$(< "$DOKKU_APP_IP_FILE")
|
|
|
|
|
local DOKKU_APP_LISTENER_PORT=$(< "$DOKKU_APP_PORT_FILE")
|
|
|
|
|
|
|
|
|
|
if [[ -z "$RAW_TCP_PORTS" ]]; then
|
|
|
|
|
local DOKKU_APP_LISTENERS+=" $DOKKU_APP_LISTENER_IP:$DOKKU_APP_LISTENER_PORT "
|
|
|
|
|
else
|
|
|
|
|
local DOKKU_APP_LISTENERS+=" $DOKKU_APP_LISTENER_IP "
|
|
|
|
|
fi
|
|
|
|
|
local DOKKU_APP_LISTENERS=$(echo $DOKKU_APP_LISTENERS | xargs)
|
|
|
|
|
local DOKKU_APP_LISTENERS=$(echo "$DOKKU_APP_LISTENERS" | xargs)
|
|
|
|
|
done
|
|
|
|
|
shopt -u nullglob
|
|
|
|
|
elif [[ -n "$DOKKU_APP_LISTEN_PORT" ]] && [[ -n "$DOKKU_APP_LISTEN_IP" ]]; then
|
|
|
|
|
local PASSED_LISTEN_IP_PORT=true
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local TMPDIR=$(mktemp -d /tmp/nginx_template.XXXXX)
|
|
|
|
|
local NGINX_CONF=$(mktemp -p ${TMPDIR} -t "nginx.conf.XXXXXX")
|
|
|
|
|
local TMPDIR=$(mktemp -d /tmp/dokku_nginx_template.XXXXX)
|
|
|
|
|
local NGINX_CONF=$(mktemp -p "${TMPDIR}" -t "nginx.conf.XXXXXX")
|
|
|
|
|
local CUSTOM_NGINX_TEMPLATE="$TMPDIR/$NGINX_TEMPLATE_NAME"
|
|
|
|
|
trap 'rm -rf "$NGINX_CONF $TMPDIR" > /dev/null' RETURN
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
trap 'rm -rf $NGINX_CONF $TMPDIR > /dev/null' RETURN INT TERM EXIT
|
|
|
|
|
|
|
|
|
|
get_custom_nginx_template "$APP" "$CUSTOM_NGINX_TEMPLATE"
|
|
|
|
|
if [[ -f "$CUSTOM_NGINX_TEMPLATE" ]]; then
|
|
|
|
|
@@ -164,23 +165,23 @@ nginx_build_config() {
|
|
|
|
|
|
|
|
|
|
# setup nginx listen ports
|
|
|
|
|
configure_nginx_ports "$APP"
|
|
|
|
|
local NGINX_PORT=$(config_get $APP DOKKU_NGINX_PORT)
|
|
|
|
|
local NGINX_SSL_PORT=$(config_get $APP DOKKU_NGINX_SSL_PORT)
|
|
|
|
|
local NGINX_PORT=$(config_get "$APP" DOKKU_NGINX_PORT)
|
|
|
|
|
local NGINX_SSL_PORT=$(config_get "$APP" DOKKU_NGINX_SSL_PORT)
|
|
|
|
|
|
|
|
|
|
local NONSSL_VHOSTS=$(get_app_domains "$APP")
|
|
|
|
|
local NOSSL_SERVER_NAME=$(echo $NONSSL_VHOSTS | xargs)
|
|
|
|
|
local NOSSL_SERVER_NAME=$(echo "$NONSSL_VHOSTS" | xargs)
|
|
|
|
|
if is_ssl_enabled "$APP"; then
|
|
|
|
|
local SSL_INUSE=true; local SCHEME=https
|
|
|
|
|
validate_ssl_domains "$APP"
|
|
|
|
|
local SSL_HOSTNAME=$(get_ssl_hostnames $APP)
|
|
|
|
|
local SSL_HOSTNAME=$(get_ssl_hostnames "$APP")
|
|
|
|
|
local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g')
|
|
|
|
|
|
|
|
|
|
if [[ "$IS_APP_VHOST_ENABLED" == "true" ]]; then
|
|
|
|
|
local SSL_VHOSTS=$(egrep "^${SSL_HOSTNAME_REGEX}$" $VHOST_PATH || true)
|
|
|
|
|
local SSL_VHOSTS=$(egrep "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" || true)
|
|
|
|
|
else
|
|
|
|
|
local SSL_VHOSTS=$(< $DOKKU_ROOT/HOSTNAME)
|
|
|
|
|
local SSL_VHOSTS=$(< "$DOKKU_ROOT/HOSTNAME")
|
|
|
|
|
fi
|
|
|
|
|
local SSL_SERVER_NAME=$(echo $SSL_VHOSTS | xargs)
|
|
|
|
|
local SSL_SERVER_NAME=$(echo "$SSL_VHOSTS" | xargs)
|
|
|
|
|
fi
|
|
|
|
|
local SIGIL_PARAMS=(-f $NGINX_TEMPLATE APP="$APP" DOKKU_ROOT="$DOKKU_ROOT"
|
|
|
|
|
NOSSL_SERVER_NAME="$NOSSL_SERVER_NAME"
|
|
|
|
|
@@ -191,29 +192,29 @@ nginx_build_config() {
|
|
|
|
|
NGINX_PORT="$NGINX_PORT" NGINX_SSL_PORT="$NGINX_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS")
|
|
|
|
|
|
|
|
|
|
# execute sigil template processing
|
|
|
|
|
xargs -i echo "-----> Configuring {}...(using $NGINX_TEMPLATE_SOURCE template)" <<< "$(echo ${SSL_VHOSTS} ${NONSSL_VHOSTS} | tr ' ' '\n' | sort -u)"
|
|
|
|
|
xargs -i echo "-----> Configuring {}...(using $NGINX_TEMPLATE_SOURCE template)" <<< "$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)"
|
|
|
|
|
# echo "sigil ${SIGIL_PARAMS[@]}"
|
|
|
|
|
sigil "${SIGIL_PARAMS[@]}" > $NGINX_CONF
|
|
|
|
|
sigil "${SIGIL_PARAMS[@]}" > "$NGINX_CONF"
|
|
|
|
|
|
|
|
|
|
if is_deployed "$APP"; then
|
|
|
|
|
dokku_log_info1 "Creating $SCHEME nginx.conf"
|
|
|
|
|
mv $NGINX_CONF "$DOKKU_ROOT/$APP/nginx.conf"
|
|
|
|
|
mv "$NGINX_CONF" "$DOKKU_ROOT/$APP/nginx.conf"
|
|
|
|
|
else
|
|
|
|
|
dokku_log_info1 "App $APP has not been deployed. Skipping nginx config creation"
|
|
|
|
|
rm -f $NGINX_CONF
|
|
|
|
|
rm -f "$NGINX_CONF"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if is_deployed "$APP"; then
|
|
|
|
|
dokku_log_info1 "Running nginx-pre-reload"
|
|
|
|
|
plugn trigger nginx-pre-reload $APP $DOKKU_APP_LISTEN_PORT $DOKKU_APP_LISTEN_IP
|
|
|
|
|
plugn trigger nginx-pre-reload "$APP" "$DOKKU_APP_LISTEN_PORT" "$DOKKU_APP_LISTEN_IP"
|
|
|
|
|
|
|
|
|
|
dokku_log_verbose "Reloading nginx"
|
|
|
|
|
validate_nginx && restart_nginx
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if ([[ -n "$NONSSL_VHOSTS" ]] || [[ -n "$SSL_VHOSTS" ]]) && [[ "$IS_APP_VHOST_ENABLED" == "true" ]]; then
|
|
|
|
|
echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" > $URLS_PATH
|
|
|
|
|
xargs -i echo "$SCHEME://{}" <<< "$(echo ${SSL_VHOSTS} ${NONSSL_VHOSTS} | tr ' ' '\n' | sort -u)" >> $URLS_PATH
|
|
|
|
|
echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" > "$URLS_PATH"
|
|
|
|
|
xargs -i echo "$SCHEME://{}" <<< "$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)" >> "$URLS_PATH"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
# note because this clause is long. if $DOKKU_DISABLE_PROXY is set:
|
|
|
|
|
|