1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2024-11-22 11:56:31 +00:00

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:
Viranch Mehta 2015-07-11 01:19:44 +05:30
parent c4923d1f58
commit 784507df1a

View File

@ -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 }};
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}}
{{ else }}
# {{$container.Name}}
server {{ $address.IP }}:{{ $address.Port }};
{{ end }}
{{ end }}
{{ end }}
{{/* Else default 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}}