allow FORCE_SSL var to set SSL preference
This commit is contained in:
parent
e47df7a884
commit
b919d95d94
1 changed files with 21 additions and 0 deletions
21
nginx.tmpl
21
nginx.tmpl
|
@ -88,6 +88,9 @@ upstream {{ $host }} {
|
|||
{{ $vhostCert := replace $vhostCert ".crt" "" -1 }}
|
||||
{{ $vhostCert := replace $vhostCert ".key" "" -1 }}
|
||||
|
||||
{{/* prefer ssl by default. override by setting FORCE_SSL: !yes */}}
|
||||
{{ $force_ssl := or (first (groupByKeys $containers "Env.FORCE_SSL")) "yes" }}
|
||||
|
||||
{{/* Use the cert specifid on the container or fallback to the best vhost match */}}
|
||||
{{ $cert := (coalesce $certName $vhostCert) }}
|
||||
|
||||
|
@ -96,7 +99,25 @@ upstream {{ $host }} {
|
|||
server {
|
||||
server_name {{ $host }};
|
||||
listen 80 {{ $default_server }};
|
||||
|
||||
{{ if eq $force_ssl "yes" }}
|
||||
return 301 https://$host$request_uri;
|
||||
{{ else }}
|
||||
|
||||
{{/* TODO use a partial for :80 block */}}
|
||||
{{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
|
||||
include {{ printf "/etc/nginx/vhost.d/%s" $host }};
|
||||
{{ end }}
|
||||
|
||||
location / {
|
||||
proxy_pass {{ $proto }}://{{ $host }};
|
||||
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
||||
auth_basic "Restricted {{ $host }}";
|
||||
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
server {
|
||||
|
|
Loading…
Reference in a new issue