|
@@ -2,24 +2,25 @@
|
|
|
|
|
|
{{ $external_http_port := coalesce $.Env.HTTP_PORT "80" }}
|
|
|
{{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }}
|
|
|
+{{ $debug_all := $.Env.DEBUG }}
|
|
|
|
|
|
{{ define "upstream" }}
|
|
|
{{ if .Address }}
|
|
|
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
|
|
|
{{ if and .Container.Node.ID .Address.HostPort }}
|
|
|
- # {{ .Container.Node.Name }}/{{ .Container.Name }}
|
|
|
+ # {{ .Container.Node.Name }}/{{ .Container.Name }}
|
|
|
server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }};
|
|
|
{{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}}
|
|
|
{{ else if .Network }}
|
|
|
- # {{ .Container.Name }}
|
|
|
- server {{ .Network.IP }}:{{ .Address.Port }};
|
|
|
+ # {{ .Container.Name }}
|
|
|
+ server {{ .Network.IP }}:{{ .Address.Port }};
|
|
|
{{ end }}
|
|
|
{{ else if .Network }}
|
|
|
- # {{ .Container.Name }}
|
|
|
+ # {{ .Container.Name }}
|
|
|
{{ if .Network.IP }}
|
|
|
- server {{ .Network.IP }} down;
|
|
|
+ server {{ .Network.IP }}:{{ .VirtualPort }};
|
|
|
{{ else }}
|
|
|
- server 127.0.0.1 down;
|
|
|
+ # /!\ No IP for this network!
|
|
|
{{ end }}
|
|
|
{{ end }}
|
|
|
|
|
@@ -180,29 +181,32 @@ server {
|
|
|
upstream {{ $upstream_name }} {
|
|
|
|
|
|
{{ range $container := $containers }}
|
|
|
- {{ $addrLen := len $container.Addresses }}
|
|
|
-
|
|
|
+ {{ $debug := (eq (coalesce $container.Env.DEBUG $debug_all "false") "true") }}
|
|
|
+ {{/* If only 1 port exposed, use that as a default, else 80 */}}
|
|
|
+ {{ $defaultPort := (when (eq (len $container.Addresses) 1) (first $container.Addresses) (dict "Port" "80")).Port }}
|
|
|
{{ range $knownNetwork := $CurrentContainer.Networks }}
|
|
|
{{ range $containerNetwork := $container.Networks }}
|
|
|
{{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
|
|
|
- ## Can be connected with "{{ $containerNetwork.Name }}" network
|
|
|
-
|
|
|
- {{/* If only 1 port exposed, use that */}}
|
|
|
- {{ if eq $addrLen 1 }}
|
|
|
- {{ $address := index $container.Addresses 0 }}
|
|
|
- {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
|
|
|
- {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}}
|
|
|
- {{ else }}
|
|
|
- {{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }}
|
|
|
- {{ $address := where $container.Addresses "Port" $port | first }}
|
|
|
- {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
|
|
|
+ ## Can be connected with "{{ $containerNetwork.Name }}" network
|
|
|
+ {{ $port := (coalesce $container.Env.VIRTUAL_PORT $defaultPort) }}
|
|
|
+ {{ $address := where $container.Addresses "Port" $port | first }}
|
|
|
+ {{ if $debug }}
|
|
|
+ # Exposed ports: {{ $container.Addresses }}
|
|
|
+ # Default virtual port: {{ $defaultPort }}
|
|
|
+ # VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }}
|
|
|
+ {{ if not $address }}
|
|
|
+ # /!\ Virtual port not exposed
|
|
|
+ {{ end }}
|
|
|
{{ end }}
|
|
|
+ {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork "VirtualPort" $port) }}
|
|
|
{{ else }}
|
|
|
- # Cannot connect to network of this container
|
|
|
- server 127.0.0.1 down;
|
|
|
+ # Cannot connect to network '{{ $containerNetwork.Name }}' of this container
|
|
|
{{ end }}
|
|
|
{{ end }}
|
|
|
{{ end }}
|
|
|
+ {{/* nginx-proxy/nginx-proxy#1105 */}}
|
|
|
+ # Fallback entry
|
|
|
+ server 127.0.0.1 down;
|
|
|
{{ end }}
|
|
|
}
|
|
|
|