Cascade two else blocks into one using coalesce on VIRTUAL_PORT and 80
This also takes care of the case when VIRTUAL_PORT is not actually exposed.
This commit is contained in:
parent
c4923d1f58
commit
784507df1a
1 changed files with 4 additions and 16 deletions
20
nginx.tmpl
20
nginx.tmpl
|
@ -54,29 +54,17 @@ upstream {{ $host }} {
|
|||
# {{$container.Name}}
|
||||
server {{ $address.IP }}:{{ $address.Port }};
|
||||
{{ end }}
|
||||
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}}
|
||||
{{ else if $container.Env.VIRTUAL_PORT }}
|
||||
{{ range $address := .Addresses }}
|
||||
{{ if eq $address.Port $container.Env.VIRTUAL_PORT }}
|
||||
{{ if and $container.Node $address.HostPort }}
|
||||
# {{ $container.Node.Name }}/{{$container.Name}}
|
||||
server {{ $container.Node.Address.IP }}:{{ $address.HostPort }};
|
||||
{{ else }}
|
||||
# {{$container.Name}}
|
||||
server {{ $address.IP }}:{{ $address.Port }};
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{/* Else default to standard web port 80 */}}
|
||||
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}}
|
||||
{{ else }}
|
||||
{{ $address := where $container.Addresses "Port" "80" | first }}
|
||||
{{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }}
|
||||
{{ $address := where $container.Addresses "Port" $port | first }}
|
||||
{{ if $address }}
|
||||
{{ if and $container.Node $address.HostPort }}
|
||||
# {{ $container.Node.Name }}/{{$container.Name}}
|
||||
server {{ $container.Node.Address.IP }}:{{ $address.HostPort }};
|
||||
{{ else }}
|
||||
# {{$container.Name}}
|
||||
server {{ $address.IP }}:80;
|
||||
server {{ $address.IP }}:{{ $address.Port }};
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
# {{$container.Name}}
|
||||
|
|
Reference in a new issue