From 6622e4cb25914370f71a3514a825b28ebdd23ee0 Mon Sep 17 00:00:00 2001 From: Abel Ferreira Date: Sat, 12 Dec 2020 20:32:42 -0300 Subject: [PATCH] allow change external https redirect port with HTTPS_REDIRECT_PORT --- README.md | 6 ++++++ nginx.tmpl | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c62a10..834afd8 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,12 @@ site after changing this setting, your browser has probably cached the HSTS poli redirecting you back to HTTPS. You will need to clear your browser's HSTS cache or use an incognito window / different browser. +### HTTPS External redirect port + +By default when `HTTPS_METHOD=redirect`. nginx will redirect connections on port HTPP 80 to default HTTPS 443 port, with `HTTPS_REDIRECT_PORT=port` you can change this behavior to another port, for example `HTTPS_REDIRECT_PORT=8443` + +### HSTS + By default, [HTTP Strict Transport Security (HSTS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security) is enabled with `max-age=31536000` for HTTPS sites. You can disable HSTS with the environment variable `HSTS=off` or use a custom HSTS configuration like `HSTS=max-age=31536000; includeSubDomains; preload`. diff --git a/nginx.tmpl b/nginx.tmpl index 07e2b50..f1aa855 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -216,6 +216,9 @@ upstream {{ $upstream_name }} { {{/* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}} {{ $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) (or $.Env.HTTPS_METHOD "redirect") }} +{{/* Get the HTTPS_REDIRECT_PORT defined by containers w/ the same vhost, falling back to "443" */}} +{{ $https_redirect_port := or (first (groupByKeys $containers "Env.HTTPS_REDIRECT_PORT")) (or $.Env.HTTPS_REDIRECT_PORT "443") }} + {{/* Get the SSL_POLICY defined by containers w/ the same vhost, falling back to empty string (use default) */}} {{ $ssl_policy := or (first (groupByKeys $containers "Env.SSL_POLICY")) "" }} @@ -262,7 +265,7 @@ server { } location / { - return 301 https://$host$request_uri; + return 301 https://$host:{{ $https_redirect_port }}$request_uri; } } {{ end }}