From 7ce72d59a98522ae1c99258ee7ec37fd8fec19d0 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 26 Dec 2023 18:18:00 +0100 Subject: [PATCH] feat: add auto keepalive setting --- nginx.tmpl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index b7a3b9a..9477928 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -292,6 +292,7 @@ {{- define "upstream" }} upstream {{ .Upstream }} { {{- $server_found := false }} + {{- $servers := 0 }} {{- $loadbalance := first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.loadbalance")) }} {{- if $loadbalance }} # From the container's loadbalance label: @@ -307,6 +308,7 @@ upstream {{ .Upstream }} { {{- $port := $args.port }} {{- if $ip }} {{- $server_found = true }} + {{- $servers = add1 $servers }} server {{ $ip }}:{{ $port }}; {{- end }} {{- end }} @@ -316,8 +318,12 @@ upstream {{ .Upstream }} { server 127.0.0.1 down; {{- end }} {{- $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 }}; + {{- end }} {{- end }} } {{- end }}