nginx.tmpl 1.8 KB

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