瀏覽代碼

fix: minor fixes on nginx template

Nicolas Duchon 3 年之前
父節點
當前提交
b6b7133a2e
共有 1 個文件被更改,包括 35 次插入35 次删除
  1. 35 35
      nginx.tmpl

+ 35 - 35
nginx.tmpl

@@ -61,8 +61,8 @@ location {{ .Path }} {
 		include uwsgi_params;
 		uwsgi_pass {{ trim .Proto }}://{{ trim .Upstream }};
 	{{ else if eq .Proto "fastcgi" }}
-		root   {{ trim .Vhostroot }};
-		include fastcgi.conf;
+		root   {{ trim .VhostRoot }};
+		include fastcgi_params;
 		fastcgi_pass {{ trim .Upstream }};
 	{{ else if eq .Proto "grpc" }}
 		grpc_pass {{ trim .Proto }}://{{ trim .Upstream }};
@@ -85,12 +85,12 @@ location {{ .Path }} {
 }
 {{ end }}
 
-{{ define "upstream-definition" }}
+{{ define "upstream" }}
 	{{ $networks := .Networks }}
 	{{ $debug_all := .Debug }}
 	upstream {{ .Upstream }} {
-		{{ $server_found := "false" }}
-		{{ range $container := .Containers }}
+	{{ $server_found := "false" }}
+	{{ range $container := .Containers }}
         {{ $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 }}
@@ -100,46 +100,46 @@ location {{ .Path }} {
         # Exposed ports: {{ $container.Addresses }}
         # Default virtual port: {{ $defaultPort }}
         # VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }}
-                {{ if not $address }}
+            {{ if not $address }}
         # /!\ Virtual port not exposed
-                {{ end }}
+            {{ end }}
         {{ end }}
-			{{ range $knownNetwork := $networks }}
-				{{ range $containerNetwork := $container.Networks }}
-					{{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
+		{{ 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 $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 }}
-                                                {{ $server_found = "true" }}
+                    {{ 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 }}
+                            {{ $server_found = "true" }}
         # {{ $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 $containerNetwork }}
-                                                {{ $server_found = "true" }}
+                        {{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}}
+                        {{ else if $containerNetwork }}
+                            {{ $server_found = "true" }}
         # {{ $container.Name }}
         server {{ $containerNetwork.IP }}:{{ $address.Port }};
-                                        {{ end }}
-                                {{ else if $containerNetwork }}
+                        {{ end }}
+                    {{ else if $containerNetwork }}
         # {{ $container.Name }}
-                                        {{ if $containerNetwork.IP }}
-                                                {{ $server_found = "true" }}
+                        {{ if $containerNetwork.IP }}
+                            {{ $server_found = "true" }}
         server {{ $containerNetwork.IP }}:{{ $port }};
-                                        {{ else }}
+                        {{ else }}
         # /!\ No IP for this network!
-                                       {{ end }}
-						{{ end }}
-					{{ else }}
-        # Cannot connect to network '{{ $containerNetwork.Name }}' of this container
+                    	{{ end }}
 					{{ end }}
+				{{ else }}
+        # Cannot connect to network '{{ $containerNetwork.Name }}' of this container
 				{{ end }}
 			{{ end }}
 		{{ end }}
-		{{/* nginx-proxy/nginx-proxy#1105 */}}
-		{{ if (eq $server_found "false") }}
+	{{ end }}
+	{{/* nginx-proxy/nginx-proxy#1105 */}}
+	{{ if (eq $server_found "false") }}
         # Fallback entry
         server 127.0.0.1 down;
-		{{ end }}
+	{{ end }}
 	}
 {{ end }}
 
@@ -263,13 +263,13 @@ server {
 
 {{ if eq $nPaths 0 }}
 	# {{ $host }}
-	{{ template "upstream-definition" (dict "Upstream" $upstream_name "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
+	{{ template "upstream" (dict "Upstream" $upstream_name "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
 {{ else }}
 	{{ range $path, $containers := $paths }}
 		{{ $sum := sha1 $path }}
 		{{ $upstream := printf "%s-%s" $upstream_name $sum }}
 		# {{ $host }}{{ $path }}
-		{{ template "upstream-definition" (dict "Upstream" $upstream "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
+		{{ template "upstream" (dict "Upstream" $upstream "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
 	{{ end }}
 {{ end }}
 
@@ -388,7 +388,7 @@ server {
 
 		{{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
 		{{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }}
-		{{ template "location" (dict "Path" "/" "Proto" $proto "Upstream" $upstream_name "Host" $host "Vhostroot" $vhost_root "Dest" "" "NetworkTag" $network_tag) }}
+		{{ template "location" (dict "Path" "/" "Proto" $proto "Upstream" $upstream_name "Host" $host "VhostRoot" $vhost_root "Dest" "" "NetworkTag" $network_tag) }}
 	{{ else }}
 		{{ range $path, $container := $paths }}
 			{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
@@ -399,7 +399,7 @@ server {
 			{{ $sum := sha1 $path }}
 			{{ $upstream := printf "%s-%s" $upstream_name $sum }}
 			{{ $dest := (or (first (groupByKeys $container "Env.VIRTUAL_DEST")) "") }}
-			{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "Vhostroot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
+			{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
 		{{ end }}
 		{{ if (not (contains $paths "/")) }}
 			location / {
@@ -436,7 +436,7 @@ server {
 
 		{{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
 		{{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }}
-		{{ template "location" (dict "Path" "/" "Proto" $proto "Upstream" $upstream_name "Host" $host "Vhostroot" $vhost_root "Dest" "" "NetworkTag" $network_tag) }}
+		{{ template "location" (dict "Path" "/" "Proto" $proto "Upstream" $upstream_name "Host" $host "VhostRoot" $vhost_root "Dest" "" "NetworkTag" $network_tag) }}
 	{{ else }}
 		{{ range $path, $container := $paths }}
 			{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
@@ -447,7 +447,7 @@ server {
 			{{ $sum := sha1 $path }}
 			{{ $upstream := printf "%s-%s" $upstream_name $sum }}
 			{{ $dest := (or (first (groupByKeys $container "Env.VIRTUAL_DEST")) "") }}
-			{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "Vhostroot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
+			{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
 		{{ end }}
 		{{ if (not (contains $paths "/")) }}
 			location / {