mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 09:48:14 +00:00
chore: Factor out duplicate virtual path code
This commit is contained in:
parent
14d0f3f222
commit
491642b1e9
46
nginx.tmpl
46
nginx.tmpl
@ -269,16 +269,18 @@ server {
|
||||
{{ $nPaths := len $paths }}
|
||||
|
||||
{{ if eq $nPaths 0 }}
|
||||
# {{ $host }}
|
||||
{{ template "upstream" (dict "Upstream" $upstream_name "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
|
||||
{{ else }}
|
||||
{{ $paths = dict "/" $containers }}
|
||||
{{ end }}
|
||||
|
||||
{{ range $path, $containers := $paths }}
|
||||
{{ $upstream := $upstream_name }}
|
||||
{{ if gt $nPaths 0 }}
|
||||
{{ $sum := sha1 $path }}
|
||||
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
||||
{{ $upstream = printf "%s-%s" $upstream $sum }}
|
||||
{{ end }}
|
||||
# {{ $host }}{{ $path }}
|
||||
{{ template "upstream" (dict "Upstream" $upstream "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ $default_host := or ($.Env.DEFAULT_HOST) "" }}
|
||||
{{ $default_server := index (dict $host "" $default_host "default_server") $host }}
|
||||
@ -389,23 +391,19 @@ server {
|
||||
include /etc/nginx/vhost.d/default;
|
||||
{{ end }}
|
||||
|
||||
{{ if eq $nPaths 0 }}
|
||||
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}}
|
||||
{{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
|
||||
|
||||
{{/* 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) }}
|
||||
{{ else }}
|
||||
{{ range $path, $containers := $paths }}
|
||||
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
|
||||
{{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
|
||||
|
||||
{{/* 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" }}
|
||||
{{ $upstream := $upstream_name }}
|
||||
{{ $dest := "" }}
|
||||
{{ if gt $nPaths 0 }}
|
||||
{{ $sum := sha1 $path }}
|
||||
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
||||
{{ $dest := (or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "") }}
|
||||
{{ $upstream = printf "%s-%s" $upstream $sum }}
|
||||
{{ $dest = (or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "") }}
|
||||
{{ end }}
|
||||
{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
|
||||
{{ end }}
|
||||
{{ if (not (contains $paths "/")) }}
|
||||
@ -413,7 +411,6 @@ server {
|
||||
return {{ $default_root_response }};
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
@ -437,23 +434,19 @@ server {
|
||||
include /etc/nginx/vhost.d/default;
|
||||
{{ end }}
|
||||
|
||||
{{ if eq $nPaths 0 }}
|
||||
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}}
|
||||
{{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
|
||||
|
||||
{{/* 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) }}
|
||||
{{ else }}
|
||||
{{ range $path, $containers := $paths }}
|
||||
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
|
||||
{{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
|
||||
|
||||
{{/* 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" }}
|
||||
{{ $upstream := $upstream_name }}
|
||||
{{ $dest := "" }}
|
||||
{{ if gt $nPaths 0 }}
|
||||
{{ $sum := sha1 $path }}
|
||||
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
||||
{{ $dest := (or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "") }}
|
||||
{{ $upstream = printf "%s-%s" $upstream $sum }}
|
||||
{{ $dest = (or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "") }}
|
||||
{{ end }}
|
||||
{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
|
||||
{{ end }}
|
||||
{{ if (not (contains $paths "/")) }}
|
||||
@ -461,7 +454,6 @@ server {
|
||||
return {{ $default_root_response }};
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user