diff --git a/nginx.tmpl b/nginx.tmpl index 649053b..4047ccb 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -68,61 +68,6 @@ {{ end }} {{ end }} -{{ define "location" }} -location {{ .Path }} { - {{ if eq .Proto "uwsgi" }} - include uwsgi_params; - uwsgi_pass {{ trim .Proto }}://{{ trim .Upstream }}; - {{ else if eq (trim .Proto) "fastcgi" }} - root {{ trim .VHostRoot }}; - include fastcgi.conf; - fastcgi_pass {{ trim .Upstream }}; - {{ else }} - proxy_pass {{ trim .Proto }}://{{ trim .Upstream }}; - {{ end }} - - {{ if (exists (printf "/etc/nginx/htpasswd/%s" .Host)) }} - auth_basic "Restricted {{ .Host }}"; - auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" .Host) }}; - {{ end }} - - {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" .Host)) }} - include {{ printf "/etc/nginx/vhost.d/%s_location" .Host}}; - {{ else if (exists "/etc/nginx/vhost.d/default_location") }} - include /etc/nginx/vhost.d/default_location; - {{ end }} -} -{{ end }} - -{{ define "upstream-definition" }} - {{ $networks := .Networks }} - upstream {{ .Upstream }} { - {{ range $container := .Containers }} - {{ $addrLen := len $container.Addresses }} - {{ range $knownNetwork := $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) }} - {{ end }} - {{ else }} - # Cannot connect to network of this container - server 127.0.0.1 down; - {{ end }} - {{ end }} - {{ end }} - {{ end }} - } -{{ end }} - {{ define "location" }} location {{ .Path }} { {{ if eq .Proto "uwsgi" }}