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 }}