Merge pull request #773 from progrium/485-native-no-vhost

Disable nginx vhosts via `dokku config:set myapp NO_VHOST=1`. Closes #485
This commit is contained in:
Jose Diaz-Gonzalez committed 2014-11-22 16:44:05 -05:00
commit 7f730d0697
2 files changed
+38 -8

No files matched your search

+10
View File
@@ -38,3 +38,13 @@ dokku nginx:import-ssl myapp < archive-of-certs.tar
``` ```
This archive should is expanded via `tar xvf`. It should contain `server.crt` and `server.key`. This archive should is expanded via `tar xvf`. It should contain `server.crt` and `server.key`.
## Disabling VHOSTS
If desired, it is possible to disable vhosts by setting the `NO_VHOST` environment variable:
```bash
dokku config:set myapp NO_VHOST=1
```
On subsequent deploys, the nginx virtualhost will be discarded. This is useful when deploying internal-facing services that should not be publicly routeable.
+28 -8
View File
@@ -5,7 +5,15 @@ APP="$1"; PORT="$2"
WILDCARD_SSL="$DOKKU_ROOT/tls" WILDCARD_SSL="$DOKKU_ROOT/tls"
SSL="$DOKKU_ROOT/$APP/tls" SSL="$DOKKU_ROOT/$APP/tls"
if [[ -f "$DOKKU_ROOT/VHOST" ]]; then set +e
NO_VHOST=$(dokku config:get $APP NO_VHOST)
set -e
if [[ -z "$NO_VHOST" ]]; then
echo "-----> NO_VHOST config detected"
fi
if [[ -f "$DOKKU_ROOT/VHOST" && ! -z "$NO_VHOST" ]]; then
VHOST=$(< "$DOKKU_ROOT/VHOST") VHOST=$(< "$DOKKU_ROOT/VHOST")
SUBDOMAIN=${APP/%\.${VHOST}/} SUBDOMAIN=${APP/%\.${VHOST}/}
if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then
@@ -26,9 +34,9 @@ EOF
SSL_DIRECTIVES="" SSL_DIRECTIVES=""
fi fi
# ssl based nginx.conf
if [[ -n "$SSL_INUSE" ]]; then if [[ -n "$SSL_INUSE" ]]; then
cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf echo "-----> creating ssl nginx.conf"
cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf
upstream $APP { server 127.0.0.1:$PORT; } upstream $APP { server 127.0.0.1:$PORT; }
server { server {
listen [::]:80; listen [::]:80;
@@ -61,10 +69,10 @@ $SSL_DIRECTIVES
} }
EOF EOF
echo "https://$hostname" > "$DOKKU_ROOT/$APP/URL" echo "https://$hostname" > "$DOKKU_ROOT/$APP/URL"
else else
# default nginx.conf echo "-----> creating non-ssl nginx.conf"
cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf
upstream $APP { server 127.0.0.1:$PORT; } upstream $APP { server 127.0.0.1:$PORT; }
server { server {
listen [::]:80; listen [::]:80;
@@ -85,10 +93,22 @@ server {
} }
EOF EOF
echo "http://$hostname" > "$DOKKU_ROOT/$APP/URL" echo "http://$hostname" > "$DOKKU_ROOT/$APP/URL"
fi fi
echo "-----> Running nginx-pre-reload" echo "-----> Running nginx-pre-reload"
pluginhook nginx-pre-reload $APP $PORT pluginhook nginx-pre-reload $APP $PORT
echo " Reloading nginx" echo " Reloading nginx"
sudo /etc/init.d/nginx reload > /dev/null sudo /etc/init.d/nginx reload > /dev/null
else
if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then
echo "------> NO_VHOST set, deleting $APP/URL"
rm "$DOKKU_ROOT/$APP/URL"
fi
if [[ -f "$DOKKU_ROOT/$APP/nginx.conf" ]]; then
echo "------> NO_VHOST set, deleting $APP/nginx.conf"
rm "$DOKKU_ROOT/$APP/nginx.conf"
echo "------> NO_VHOST set, reloading nginx after nginx.conf deletion"
sudo /etc/init.d/nginx reload > /dev/null
fi
fi fi