diff --git a/dokku b/dokku index 0dbeba176..6c16f0b3b 100755 --- a/dokku +++ b/dokku @@ -36,7 +36,7 @@ case "$1" in echo "-----> Deploying $APP ..." dokku deploy $APP echo "=====> Application deployed:" - echo "$(dokku url $APP | sed "s/^/ /")" + echo "$(dokku urls $APP | sed "s/^/ /")" echo ;; diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index ac55d4c8a..403b40c15 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -34,13 +34,26 @@ case "$1" in docker run -i -t $DOCKER_ARGS $IMAGE /exec "$@" ;; - url) + url | urls) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 - APP="$2"; + APP="$2"; SCHEME="http"; SSL="$DOKKU_ROOT/$APP/tls" + + if [[ -e "$SSL/server.crt" ]] && [[ -e "$SSL/server.key" ]]; then + SCHEME="https" + fi if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then - cat "$DOKKU_ROOT/$APP/VHOST" + case "$1" in + url) + echo "$SCHEME://$(head -n1 "$DOKKU_ROOT/$APP/VHOST")" + ;; + urls) + for vhost in $(< "$DOKKU_ROOT/$APP/VHOST"); do + echo "$SCHEME://$vhost" + done + ;; + esac fi ;; @@ -55,7 +68,8 @@ case "$1" in cat && cat< [-t] Show the last logs for an application (-t follows) run Run a command in the environment of an application - url Show the URL for an application + url Show the first URL for an application (compatibility) + urls Show all URLs for an application version Print dokku's version EOF ;; diff --git a/plugins/domains/commands b/plugins/domains/commands index 68e220ce2..14c7b01a8 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -55,7 +55,6 @@ case "$1" in pluginhook post-domains-update $APP echo "-----> Added $3 to $APP" - dokku nginx:build-config $APP ;; domains:clear) @@ -63,12 +62,11 @@ case "$1" in [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" + rm -f "$DOKKU_ROOT/$APP/VHOST" dokku domains:setup $APP - echo '' > "$DOKKU_ROOT/$APP/VHOST" pluginhook post-domains-update $APP echo "-----> Cleared domains in $APP" - dokku nginx:build-config $APP ;; domains:remove) @@ -87,7 +85,6 @@ case "$1" in pluginhook post-domains-update $APP echo "-----> Removed $3 from $APP" - dokku nginx:build-config $APP ;; help | domains:help) diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 7052de158..c961bc5f0 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -43,8 +43,8 @@ EOF SSL_HOSTNAME=`openssl x509 -in $SSL_INUSE/server.crt -noout -subject | tr '/' '\n' | grep CN= | cut -c4-` SSL_HOSTNAME=`echo "$SSL_HOSTNAME" | sed 's|\.|\\.|g' | sed 's/\*/\.\*/g'` - SSL_VHOSTS=`grep "$SSL_HOSTNAME" $VHOST_PATH` - NONSSL_VHOSTS=`grep -v "$SSL_HOSTNAME" $VHOST_PATH` + SSL_VHOSTS=`egrep ^"$SSL_HOSTNAME"$ $VHOST_PATH` + NONSSL_VHOSTS=`egrep -v ^"$SSL_HOSTNAME"$ $VHOST_PATH || exit 0` while read line; do echo "-----> Configuring SSL for $line..." @@ -60,7 +60,8 @@ EOF fi cat $VHOST_PATH | xargs -i echo "-----> Configuring {}..." - NOSSL_SERVER_NAME=`echo $NONSSL_VHOSTS | tr '\n' ' '` + # Include SSL_VHOSTS so we can redirect http to https on that hostname as well + NOSSL_SERVER_NAME=`echo $NONSSL_VHOSTS $SSL_VHOSTS| tr '\n' ' '` echo "-----> Creating $SCHEME nginx.conf" echo "upstream $APP { server 127.0.0.1:$PORT; }" > $DOKKU_ROOT/$APP/nginx.conf @@ -101,7 +102,9 @@ EOF mkdir -p "$DOKKU_ROOT/$APP/tls" mv "$TEMP_DIR/server.crt" "$DOKKU_ROOT/$APP/tls/server.crt" mv "$TEMP_DIR/server.key" "$DOKKU_ROOT/$APP/tls/server.key" + cd $DOKKU_ROOT rm -rf $TEMP_DIR + dokku nginx:build-config $APP ;; help | nginx:help) diff --git a/plugins/nginx-vhosts/post-domains-update b/plugins/nginx-vhosts/post-domains-update new file mode 100755 index 000000000..e2bb35ebd --- /dev/null +++ b/plugins/nginx-vhosts/post-domains-update @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +APP="$1" + +dokku nginx:build-config $APP diff --git a/plugins/nginx-vhosts/templates/nginx.ssl.conf b/plugins/nginx-vhosts/templates/nginx.ssl.conf index e30a6a82d..5cde7484a 100644 --- a/plugins/nginx-vhosts/templates/nginx.ssl.conf +++ b/plugins/nginx-vhosts/templates/nginx.ssl.conf @@ -2,7 +2,7 @@ server { listen [::]:80; listen 80; server_name $NOSSL_SERVER_NAME; - return 301 https://\$host\$request_uri; + return 301 https://$SSL_SERVER_NAME\$request_uri; } server {