mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 01:38:15 +00:00
refactor: get rid of get_path_info template
This commit is contained in:
parent
8359aa2089
commit
0baff189bc
67
nginx.tmpl
67
nginx.tmpl
@ -338,44 +338,6 @@ upstream {{ $vpath.upstream }} {
|
|||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{- /*
|
|
||||||
* Template used as a function to collect virtual path properties from
|
|
||||||
* the given containers. These properties are "returned" by storing their
|
|
||||||
* values into the provided dot dict.
|
|
||||||
*
|
|
||||||
* The provided dot dict is expected to have the following entries:
|
|
||||||
* - "Containers": List of container's RuntimeContainer struct.
|
|
||||||
* - "Upstream_name"
|
|
||||||
* - "Path"
|
|
||||||
*
|
|
||||||
* The return values will be added to the dot dict with keys:
|
|
||||||
* - "proto"
|
|
||||||
* - "network_tag"
|
|
||||||
* - "upstream"
|
|
||||||
* - "loadbalance"
|
|
||||||
* - "keepalive"
|
|
||||||
*/}}
|
|
||||||
{{- define "get_path_info" }}
|
|
||||||
{{- /* 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" }}
|
|
||||||
|
|
||||||
{{- $loadbalance := first (keys (groupByLabel $.Containers "com.github.nginx-proxy.nginx-proxy.loadbalance")) }}
|
|
||||||
{{- $keepalive := coalesce (first (keys (groupByLabel $.Containers "com.github.nginx-proxy.nginx-proxy.keepalive"))) "disabled" }}
|
|
||||||
|
|
||||||
{{- $upstream := $.Upstream_name }}
|
|
||||||
{{- if (not (eq $.Path "/")) }}
|
|
||||||
{{- $sum := sha1 $.Path }}
|
|
||||||
{{- $upstream = printf "%s-%s" $upstream $sum }}
|
|
||||||
{{- end }}
|
|
||||||
{{- $_ := set $ "proto" $proto }}
|
|
||||||
{{- $_ := set $ "network_tag" $network_tag }}
|
|
||||||
{{- $_ := set $ "upstream" $upstream }}
|
|
||||||
{{- $_ := set $ "loadbalance" $loadbalance }}
|
|
||||||
{{- $_ := set $ "keepalive" $keepalive }}
|
|
||||||
{{- end }}
|
|
||||||
|
|
||||||
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
|
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
|
||||||
# scheme used to connect to this server
|
# scheme used to connect to this server
|
||||||
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
|
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
|
||||||
@ -586,18 +548,25 @@ proxy_set_header Proxy "";
|
|||||||
{{ $vpath_containers = concat $vpath_containers $vport_containers }}
|
{{ $vpath_containers = concat $vpath_containers $vport_containers }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{- $args := (dict
|
{{- /* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http". */}}
|
||||||
"Containers" $vpath_containers
|
{{- $proto := trim (or (first (groupByKeys $vpath_containers "Env.VIRTUAL_PROTO")) "http") }}
|
||||||
"Path" $path
|
{{- /* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external". */}}
|
||||||
"Upstream_name" $vhost_data.upstream_name
|
{{- $network_tag := or (first (groupByKeys $vpath_containers "Env.NETWORK_ACCESS")) "external" }}
|
||||||
)}}
|
|
||||||
|
|
||||||
{{- template "get_path_info" $args }}
|
{{- $loadbalance := first (keys (groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.loadbalance")) }}
|
||||||
{{- $_ := set $vpath_data "proto" $args.proto }}
|
{{- $keepalive := coalesce (first (keys (groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.keepalive"))) "disabled" }}
|
||||||
{{- $_ := set $vpath_data "network_tag" $args.network_tag }}
|
|
||||||
{{- $_ := set $vpath_data "upstream" $args.upstream }}
|
{{- $upstream := $vhost_data.upstream_name }}
|
||||||
{{- $_ := set $vpath_data "loadbalance" $args.loadbalance }}
|
{{- if (not (eq $path "/")) }}
|
||||||
{{- $_ := set $vpath_data "keepalive" $args.keepalive }}
|
{{- $sum := sha1 $path }}
|
||||||
|
{{- $upstream = printf "%s-%s" $upstream $sum }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- $_ := set $vpath_data "proto" $proto }}
|
||||||
|
{{- $_ := set $vpath_data "network_tag" $network_tag }}
|
||||||
|
{{- $_ := set $vpath_data "upstream" $upstream }}
|
||||||
|
{{- $_ := set $vpath_data "loadbalance" $loadbalance }}
|
||||||
|
{{- $_ := set $vpath_data "keepalive" $keepalive }}
|
||||||
{{- $_ := set $vhost_data.paths $path $vpath_data }}
|
{{- $_ := set $vhost_data.paths $path $vpath_data }}
|
||||||
|
|
||||||
{{ $vhost_containers = concat $vhost_containers $vpath_containers }}
|
{{ $vhost_containers = concat $vhost_containers $vpath_containers }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user