1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-02-24 09:48:14 +00:00

feat: add auto keepalive setting

This commit is contained in:
Nicolas Duchon 2023-12-26 18:18:00 +01:00
parent 26db13387e
commit 7ce72d59a9

View File

@ -292,6 +292,7 @@
{{- define "upstream" }} {{- define "upstream" }}
upstream {{ .Upstream }} { upstream {{ .Upstream }} {
{{- $server_found := false }} {{- $server_found := false }}
{{- $servers := 0 }}
{{- $loadbalance := first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.loadbalance")) }} {{- $loadbalance := first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.loadbalance")) }}
{{- if $loadbalance }} {{- if $loadbalance }}
# From the container's loadbalance label: # From the container's loadbalance label:
@ -307,6 +308,7 @@ upstream {{ .Upstream }} {
{{- $port := $args.port }} {{- $port := $args.port }}
{{- if $ip }} {{- if $ip }}
{{- $server_found = true }} {{- $server_found = true }}
{{- $servers = add1 $servers }}
server {{ $ip }}:{{ $port }}; server {{ $ip }}:{{ $port }};
{{- end }} {{- end }}
{{- end }} {{- end }}
@ -316,8 +318,12 @@ upstream {{ .Upstream }} {
server 127.0.0.1 down; server 127.0.0.1 down;
{{- end }} {{- end }}
{{- $keepalive := coalesce (first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.keepalive"))) "disabled" }} {{- $keepalive := coalesce (first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.keepalive"))) "disabled" }}
{{- if ne $keepalive "disabled" }} {{- if and (ne $keepalive "disabled") (gt $servers 0) }}
{{- if eq $keepalive "auto" }}
keepalive {{ mul $servers 2 }};
{{- else }}
keepalive {{ $keepalive }}; keepalive {{ $keepalive }};
{{- end }}
{{- end }} {{- end }}
} }
{{- end }} {{- end }}