mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 01:38:15 +00:00
fix: minor fixes on nginx template
This commit is contained in:
parent
01446472dd
commit
b6b7133a2e
70
nginx.tmpl
70
nginx.tmpl
@ -61,8 +61,8 @@ location {{ .Path }} {
|
|||||||
include uwsgi_params;
|
include uwsgi_params;
|
||||||
uwsgi_pass {{ trim .Proto }}://{{ trim .Upstream }};
|
uwsgi_pass {{ trim .Proto }}://{{ trim .Upstream }};
|
||||||
{{ else if eq .Proto "fastcgi" }}
|
{{ else if eq .Proto "fastcgi" }}
|
||||||
root {{ trim .Vhostroot }};
|
root {{ trim .VhostRoot }};
|
||||||
include fastcgi.conf;
|
include fastcgi_params;
|
||||||
fastcgi_pass {{ trim .Upstream }};
|
fastcgi_pass {{ trim .Upstream }};
|
||||||
{{ else if eq .Proto "grpc" }}
|
{{ else if eq .Proto "grpc" }}
|
||||||
grpc_pass {{ trim .Proto }}://{{ trim .Upstream }};
|
grpc_pass {{ trim .Proto }}://{{ trim .Upstream }};
|
||||||
@ -85,12 +85,12 @@ location {{ .Path }} {
|
|||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "upstream-definition" }}
|
{{ define "upstream" }}
|
||||||
{{ $networks := .Networks }}
|
{{ $networks := .Networks }}
|
||||||
{{ $debug_all := .Debug }}
|
{{ $debug_all := .Debug }}
|
||||||
upstream {{ .Upstream }} {
|
upstream {{ .Upstream }} {
|
||||||
{{ $server_found := "false" }}
|
{{ $server_found := "false" }}
|
||||||
{{ range $container := .Containers }}
|
{{ range $container := .Containers }}
|
||||||
{{ $debug := (eq (coalesce $container.Env.DEBUG $debug_all "false") "true") }}
|
{{ $debug := (eq (coalesce $container.Env.DEBUG $debug_all "false") "true") }}
|
||||||
{{/* If only 1 port exposed, use that as a default, else 80 */}}
|
{{/* 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 }}
|
{{ $defaultPort := (when (eq (len $container.Addresses) 1) (first $container.Addresses) (dict "Port" "80")).Port }}
|
||||||
@ -100,46 +100,46 @@ location {{ .Path }} {
|
|||||||
# Exposed ports: {{ $container.Addresses }}
|
# Exposed ports: {{ $container.Addresses }}
|
||||||
# Default virtual port: {{ $defaultPort }}
|
# Default virtual port: {{ $defaultPort }}
|
||||||
# VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }}
|
# VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }}
|
||||||
{{ if not $address }}
|
{{ if not $address }}
|
||||||
# /!\ Virtual port not exposed
|
# /!\ Virtual port not exposed
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ range $knownNetwork := $networks }}
|
{{ range $knownNetwork := $networks }}
|
||||||
{{ range $containerNetwork := $container.Networks }}
|
{{ range $containerNetwork := $container.Networks }}
|
||||||
{{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
|
{{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
|
||||||
## Can be connected with "{{ $containerNetwork.Name }}" network
|
## Can be connected with "{{ $containerNetwork.Name }}" network
|
||||||
{{ if $address }}
|
{{ if $address }}
|
||||||
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
|
{{/* 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 }}
|
{{ if and $container.Node.ID $address.HostPort }}
|
||||||
{{ $server_found = "true" }}
|
{{ $server_found = "true" }}
|
||||||
# {{ $container.Node.Name }}/{{ $container.Name }}
|
# {{ $container.Node.Name }}/{{ $container.Name }}
|
||||||
server {{ $container.Node.Address.IP }}:{{ $address.HostPort }};
|
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 */}}
|
{{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}}
|
||||||
{{ else if $containerNetwork }}
|
{{ else if $containerNetwork }}
|
||||||
{{ $server_found = "true" }}
|
{{ $server_found = "true" }}
|
||||||
# {{ $container.Name }}
|
# {{ $container.Name }}
|
||||||
server {{ $containerNetwork.IP }}:{{ $address.Port }};
|
server {{ $containerNetwork.IP }}:{{ $address.Port }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ else if $containerNetwork }}
|
{{ else if $containerNetwork }}
|
||||||
# {{ $container.Name }}
|
# {{ $container.Name }}
|
||||||
{{ if $containerNetwork.IP }}
|
{{ if $containerNetwork.IP }}
|
||||||
{{ $server_found = "true" }}
|
{{ $server_found = "true" }}
|
||||||
server {{ $containerNetwork.IP }}:{{ $port }};
|
server {{ $containerNetwork.IP }}:{{ $port }};
|
||||||
{{ else }}
|
{{ else }}
|
||||||
# /!\ No IP for this network!
|
# /!\ No IP for this network!
|
||||||
{{ end }}
|
{{ 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 }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{/* nginx-proxy/nginx-proxy#1105 */}}
|
{{ end }}
|
||||||
{{ if (eq $server_found "false") }}
|
{{/* nginx-proxy/nginx-proxy#1105 */}}
|
||||||
|
{{ if (eq $server_found "false") }}
|
||||||
# Fallback entry
|
# Fallback entry
|
||||||
server 127.0.0.1 down;
|
server 127.0.0.1 down;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
@ -263,13 +263,13 @@ server {
|
|||||||
|
|
||||||
{{ if eq $nPaths 0 }}
|
{{ if eq $nPaths 0 }}
|
||||||
# {{ $host }}
|
# {{ $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 }}
|
{{ else }}
|
||||||
{{ range $path, $containers := $paths }}
|
{{ range $path, $containers := $paths }}
|
||||||
{{ $sum := sha1 $path }}
|
{{ $sum := sha1 $path }}
|
||||||
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
||||||
# {{ $host }}{{ $path }}
|
# {{ $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 }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ server {
|
|||||||
|
|
||||||
{{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
|
{{/* 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" }}
|
{{ $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 }}
|
{{ else }}
|
||||||
{{ range $path, $container := $paths }}
|
{{ range $path, $container := $paths }}
|
||||||
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
|
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
|
||||||
@ -399,7 +399,7 @@ server {
|
|||||||
{{ $sum := sha1 $path }}
|
{{ $sum := sha1 $path }}
|
||||||
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
||||||
{{ $dest := (or (first (groupByKeys $container "Env.VIRTUAL_DEST")) "") }}
|
{{ $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 }}
|
{{ end }}
|
||||||
{{ if (not (contains $paths "/")) }}
|
{{ if (not (contains $paths "/")) }}
|
||||||
location / {
|
location / {
|
||||||
@ -436,7 +436,7 @@ server {
|
|||||||
|
|
||||||
{{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
|
{{/* 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" }}
|
{{ $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 }}
|
{{ else }}
|
||||||
{{ range $path, $container := $paths }}
|
{{ range $path, $container := $paths }}
|
||||||
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
|
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
|
||||||
@ -447,7 +447,7 @@ server {
|
|||||||
{{ $sum := sha1 $path }}
|
{{ $sum := sha1 $path }}
|
||||||
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
||||||
{{ $dest := (or (first (groupByKeys $container "Env.VIRTUAL_DEST")) "") }}
|
{{ $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 }}
|
{{ end }}
|
||||||
{{ if (not (contains $paths "/")) }}
|
{{ if (not (contains $paths "/")) }}
|
||||||
location / {
|
location / {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user