nginx.tmpl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. server {
  2. listen 80 default_server;
  3. server_name _; # This is just an invalid value which will never trigger on a real hostname.
  4. error_log /proc/self/fd/2;
  5. access_log /proc/self/fd/1;
  6. return 503;
  7. }
  8. {{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
  9. upstream {{ $host }} {
  10. {{ range $index, $value := $containers }}
  11. {{ $addrLen := len $value.Addresses }}
  12. {{/* If only 1 port exposed, use that */}}
  13. {{ if eq $addrLen 1 }}
  14. {{ with $address := index $value.Addresses 0 }}
  15. # {{$value.Name}}
  16. server {{ $address.IP }}:{{ $address.Port }};
  17. {{ end }}
  18. {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}}
  19. {{ else if $value.Env.VIRTUAL_PORT }}
  20. {{ range $i, $address := $value.Addresses }}
  21. {{ if eq $address.Port $value.Env.VIRTUAL_PORT }}
  22. # {{$value.Name}}
  23. server {{ $address.IP }}:{{ $address.Port }};
  24. {{ end }}
  25. {{ end }}
  26. {{/* Else default to standard web port 80 */}}
  27. {{ else }}
  28. {{ range $i, $address := $value.Addresses }}
  29. {{ if eq $address.Port "80" }}
  30. # {{$value.Name}}
  31. server {{ $address.IP }}:{{ $address.Port }};
  32. {{ end }}
  33. {{ end }}
  34. {{ end }}
  35. {{ end }}
  36. }
  37. server {
  38. gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  39. server_name {{ $host }};
  40. proxy_buffering off;
  41. error_log /proc/self/fd/2;
  42. access_log /proc/self/fd/1;
  43. location / {
  44. proxy_pass http://{{ $host }};
  45. include /etc/nginx/proxy_params;
  46. # HTTP 1.1 support
  47. proxy_http_version 1.1;
  48. proxy_set_header Connection "";
  49. }
  50. }
  51. {{ end }}