Merge pull request #823 from expa/nginx-cleanup

show URLS with scheme. now with bug fixes!!!
This commit is contained in:
Jose Diaz-Gonzalez
2014-12-16 16:26:47 -05:00
6 changed files with 33 additions and 13 deletions

2
dokku
View File

@@ -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
;;

View File

@@ -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<<EOF
logs <app> [-t] Show the last logs for an application (-t follows)
run <app> <cmd> Run a command in the environment of an application
url <app> Show the URL for an application
url <app> Show the first URL for an application (compatibility)
urls <app> Show all URLs for an application
version Print dokku's version
EOF
;;

View File

@@ -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)

View File

@@ -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)

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
APP="$1"
dokku nginx:build-config $APP

View File

@@ -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 {