diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 2add2e4f0..1964b45b9 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -69,6 +69,7 @@ configure_nginx_ports() { local DOKKU_NGINX_SSL_PORT=$(config_get "$APP" DOKKU_NGINX_SSL_PORT) local DOKKU_PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP) local IS_APP_VHOST_ENABLED="$(is_app_vhost_enabled "$APP")" + local UPSTREAM_PORT="5000" if [[ -z "$DOKKU_NGINX_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then @@ -77,8 +78,8 @@ configure_nginx_ports() { else local NGINX_PORT=80 fi + config_set --no-restart "$APP" DOKKU_NGINX_PORT="$NGINX_PORT" fi - if [[ -z "$DOKKU_NGINX_SSL_PORT" ]]; then if (is_ssl_enabled "$APP") && [[ -z "$RAW_TCP_PORTS" ]]; then if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then @@ -88,8 +89,8 @@ configure_nginx_ports() { local NGINX_SSL_PORT=443 fi fi + config_set --no-restart "$APP" DOKKU_NGINX_SSL_PORT="$NGINX_SSL_PORT" fi - if [[ -z "$DOKKU_PROXY_PORT_MAP" ]]; then if [[ -n "$RAW_TCP_PORTS" ]]; then local RAW_TCP_PORT @@ -99,14 +100,13 @@ configure_nginx_ports() { else local NGINX_PORT=${NGINX_PORT:-$DOKKU_NGINX_PORT} local NGINX_SSL_PORT=${NGINX_SSL_PORT:-$DOKKU_NGINX_SSL_PORT} - + [[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]] && local UPSTREAM_PORT="$(< "$DOKKU_ROOT/$APP/PORT.web.1")" if [[ -n "$NGINX_PORT" ]] && [[ -n "$NGINX_SSL_PORT" ]]; then - local PROXY_PORT_MAP+=" http:${NGINX_PORT}:5000 https:${NGINX_SSL_PORT}:5000 " + local PROXY_PORT_MAP+=" http:${NGINX_PORT}:$UPSTREAM_PORT https:${NGINX_SSL_PORT}:$UPSTREAM_PORT " elif [[ -n "$NGINX_PORT" ]]; then - local PROXY_PORT_MAP+=" http:${NGINX_PORT}:5000 " + local PROXY_PORT_MAP+=" http:${NGINX_PORT}:$UPSTREAM_PORT " fi fi - if [[ -n "$PROXY_PORT_MAP" ]]; then local PROXY_PORT_MAP="$(echo "$PROXY_PORT_MAP" | xargs)" local PROXY_PORT_MAP+=" $(merge_dedupe_list "$(remove_val_from_list "$PORT_MAP" "$DOKKU_PROXY_PORT_MAP" " ")" " ") " diff --git a/plugins/nginx-vhosts/templates/nginx.conf.sigil b/plugins/nginx-vhosts/templates/nginx.conf.sigil index 931604bbe..6ac5d721b 100644 --- a/plugins/nginx-vhosts/templates/nginx.conf.sigil +++ b/plugins/nginx-vhosts/templates/nginx.conf.sigil @@ -11,8 +11,7 @@ server { {{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }} access_log /var/log/nginx/{{ $.APP }}-access.log; error_log /var/log/nginx/{{ $.APP }}-error.log; -{{ if $.SSL_INUSE }} -{{ if eq $listen_port "80" }} +{{ if (and (eq $listen_port "80") ($.SSL_INUSE)) }} return 301 https://$host:{{ $.NGINX_SSL_PORT }}$request_uri; {{ else }} location / { @@ -35,7 +34,7 @@ server { proxy_set_header X-Request-Start $msec; } include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf; -{{ end }}{{ end }} +{{ end }} } {{ else if eq $scheme "https"}} server { diff --git a/tests/unit/40_core_2.bats b/tests/unit/40_core_2.bats index e8cc44671..b3d860243 100644 --- a/tests/unit/40_core_2.bats +++ b/tests/unit/40_core_2.bats @@ -57,20 +57,20 @@ build_nginx_config() { setup_test_tls assert_urls "https://dokku.me" build_nginx_config - assert_urls "https://${TEST_APP}.dokku.me" + assert_urls "http://${TEST_APP}.dokku.me" "https://${TEST_APP}.dokku.me" add_domain "test.dokku.me" - assert_urls "https://test.dokku.me" "https://${TEST_APP}.dokku.me" + assert_urls "http://test.dokku.me" "http://${TEST_APP}.dokku.me" "https://test.dokku.me" "https://${TEST_APP}.dokku.me" } @test "(core) urls (wildcard ssl)" { setup_test_tls wildcard assert_urls "https://dokku.me" build_nginx_config - assert_urls "https://${TEST_APP}.dokku.me" + assert_urls "http://${TEST_APP}.dokku.me" "https://${TEST_APP}.dokku.me" add_domain "test.dokku.me" - assert_urls "https://test.dokku.me" "https://${TEST_APP}.dokku.me" + assert_urls "http://test.dokku.me" "http://${TEST_APP}.dokku.me" "https://test.dokku.me" "https://${TEST_APP}.dokku.me" add_domain "dokku.example.com" - assert_urls "https://dokku.example.com" "https://test.dokku.me" "https://${TEST_APP}.dokku.me" + assert_urls "http://dokku.example.com" "http://test.dokku.me" "http://${TEST_APP}.dokku.me" "https://dokku.example.com" "https://test.dokku.me" "https://${TEST_APP}.dokku.me" } @test "(core) git-remote (off-port)" {