Skip to content

Commit

Permalink
Deal with networks (supports new overlay network)
Browse files Browse the repository at this point in the history
  • Loading branch information
baptistedonaux committed Jan 15, 2016
1 parent 18e1821 commit 6218579
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions templates/nginx.tmpl
Expand Up @@ -12,28 +12,30 @@ upstream {{ $host }} {
{{ range $index, $value := $containers }}

{{ $addrLen := len $value.Addresses }}
{{ $network := index $value.Networks 0 }}

{{/* If only 1 port exposed, use that */}}
{{ if eq $addrLen 1 }}
{{ with $address := index $value.Addresses 0 }}
# {{$value.Name}}
server {{ $address.IP }}:{{ $address.Port }};
# {{$value.Name}}
server {{ $network.IP }}:{{ $address.Port }};
{{ end }}

{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}}
{{ else if $value.Env.VIRTUAL_PORT }}
{{ range $i, $address := $value.Addresses }}
{{ if eq $address.Port $value.Env.VIRTUAL_PORT }}
# {{$value.Name}}
server {{ $address.IP }}:{{ $address.Port }};
{{ end }}
{{ if eq $address.Port $value.Env.VIRTUAL_PORT }}
# {{$value.Name}}
server {{ $network.IP }}:{{ $address.Port }};
{{ end }}
{{ end }}

{{/* Else default to standard web port 80 */}}
{{ else }}
{{ range $i, $address := $value.Addresses }}
{{ if eq $address.Port "80" }}
# {{$value.Name}}
server {{ $address.IP }}:{{ $address.Port }};
server {{ $network.IP }}:{{ $address.Port }};
{{ end }}
{{ end }}
{{ end }}
Expand Down

0 comments on commit 6218579

Please sign in to comment.