Added support for specifying destination protocol and port for each src virtual hosts. The syntax is used in the VIRTUAL_HOST env variable. Like this VIRTUAL_HOST=www.example.com=>https:8443,admin.example.com=>https:8444
This commit is contained in:
parent
0ef8dca98c
commit
0fa127f7bb
1 changed files with 9 additions and 3 deletions
12
nginx.tmpl
12
nginx.tmpl
|
@ -72,7 +72,13 @@ server {
|
|||
}
|
||||
{{ end }}
|
||||
|
||||
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
|
||||
{{ range $opt, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
|
||||
{{ $parts := split $opt "=>"}}
|
||||
{{ $host := first $parts | trim }}
|
||||
{{ $dest := last $parts | trim }}
|
||||
{{ $destParts := split (when (ne $host $dest) $dest ":") ":" }}
|
||||
{{ $destProto := first $destParts }}
|
||||
{{ $destPort := last $destParts }}
|
||||
|
||||
upstream {{ $host }} {
|
||||
{{ range $container := $containers }}
|
||||
|
@ -89,7 +95,7 @@ upstream {{ $host }} {
|
|||
{{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
|
||||
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}}
|
||||
{{ else }}
|
||||
{{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }}
|
||||
{{ $port := coalesce $container.Env.VIRTUAL_PORT "80" | or $destPort }}
|
||||
{{ $address := where $container.Addresses "Port" $port | first }}
|
||||
{{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
|
||||
{{ end }}
|
||||
|
@ -103,7 +109,7 @@ upstream {{ $host }} {
|
|||
{{ $default_server := index (dict $host "" $default_host "default_server") $host }}
|
||||
|
||||
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}}
|
||||
{{ $proto := or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http" }}
|
||||
{{ $proto := or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http" | or $destProto }}
|
||||
|
||||
{{/* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}}
|
||||
{{ $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) "redirect" }}
|
||||
|
|
Loading…
Reference in a new issue