nginx.tmpl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. {{ range $host, $containers := groupBy $ "Env.VIRTUAL_HOST" }}
  2. upstream {{ $host }} {
  3. {{ range $index, $value := $containers }}
  4. {{ $addrLen := len $value.Addresses }}
  5. {{/* If only 1 port exposed, use that */}}
  6. {{ if eq $addrLen 1 }}
  7. {{ with $address := index $value.Addresses 0 }}
  8. # {{$value.Name}}
  9. server {{ $address.IP }}:{{ $address.Port }};
  10. {{ end }}
  11. {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}}
  12. {{ else if $value.Env.VIRTUAL_PORT }}
  13. {{ range $i, $address := $value.Addresses }}
  14. {{ if eq $address.Port $value.Env.VIRTUAL_PORT }}
  15. # {{$value.Name}}
  16. server {{ $address.IP }}:{{ $address.Port }};
  17. {{ end }}
  18. {{ end }}
  19. {{/* Else default to standard web port 80 */}}
  20. {{ else }}
  21. {{ range $i, $address := $value.Addresses }}
  22. {{ if eq $address.Port "80" }}
  23. # {{$value.Name}}
  24. server {{ $address.IP }}:{{ $address.Port }};
  25. {{ end }}
  26. {{ end }}
  27. {{ end }}
  28. {{ end }}
  29. }
  30. server {
  31. gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  32. server_name {{ $host }};
  33. proxy_buffering off;
  34. location / {
  35. proxy_pass http://{{ $host }};
  36. include /etc/nginx/proxy_params;
  37. }
  38. }
  39. {{ end }}