From 78d3921a6f62b50481344a4c5e38de2f55e5d60b Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Mon, 15 Dec 2014 13:15:40 -0800 Subject: [PATCH 1/5] don't break other nginx plugins like nginx-alt --- plugins/domains/commands | 3 --- plugins/nginx-vhosts/post-domains-update | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100755 plugins/nginx-vhosts/post-domains-update diff --git a/plugins/domains/commands b/plugins/domains/commands index 68e220ce2..80d1c1603 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) @@ -68,7 +67,6 @@ case "$1" in 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/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 From 50115d3640a89e107d42a5fe035a9c1fb659c0f8 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Mon, 15 Dec 2014 18:02:57 -0800 Subject: [PATCH 2/5] print out urls with scheme --- dokku | 2 +- plugins/00_dokku-standard/commands | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) 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 ;; From a6cdae5abf2f2eda09d0bb955237ec1b6c00d350 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Mon, 15 Dec 2014 18:04:00 -0800 Subject: [PATCH 3/5] reset VHOST to default upon domains:clear --- plugins/domains/commands | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/domains/commands b/plugins/domains/commands index 80d1c1603..14c7b01a8 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -62,8 +62,8 @@ 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" From 1b208778f335a513aa6e33ce40e49983f54b3987 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Mon, 15 Dec 2014 18:10:14 -0800 Subject: [PATCH 4/5] bugfixes - don't match substrings in VHOSTS - handle case where NOSSL_SERVER_NAME is \' \' - rebuild nginx config on ssl import - prevent cwd errors after we rm the temp dir --- plugins/nginx-vhosts/commands | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 7052de158..64f88f947 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..." @@ -61,6 +61,8 @@ EOF cat $VHOST_PATH | xargs -i echo "-----> Configuring {}..." NOSSL_SERVER_NAME=`echo $NONSSL_VHOSTS | tr '\n' ' '` + # if NOSSL_SERVER_NAME is just ' ' then set NOSSL_SERVER_NAME to SSL_HOSTNAME since we redirect anyway + [[ "$NOSSL_SERVER_NAME" = ' ' ]] && NOSSL_SERVER_NAME=$(echo $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 +103,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) From 59f047bb453e029c16235a62959d144c5093768a Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Tue, 16 Dec 2014 12:15:10 -0800 Subject: [PATCH 5/5] include SSL_VHOSTS in NOSSL_SERVER_NAME so we can redirect from http to https on the secure hostname as well --- plugins/nginx-vhosts/commands | 5 ++--- plugins/nginx-vhosts/templates/nginx.ssl.conf | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 64f88f947..c961bc5f0 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -60,9 +60,8 @@ EOF fi cat $VHOST_PATH | xargs -i echo "-----> Configuring {}..." - NOSSL_SERVER_NAME=`echo $NONSSL_VHOSTS | tr '\n' ' '` - # if NOSSL_SERVER_NAME is just ' ' then set NOSSL_SERVER_NAME to SSL_HOSTNAME since we redirect anyway - [[ "$NOSSL_SERVER_NAME" = ' ' ]] && NOSSL_SERVER_NAME=$(echo $SSL_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 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 {