|
69 | 69 | {{- end }}
|
70 | 70 |
|
71 | 71 | {{- define "location" }}
|
| 72 | + {{- $keepalive := first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.keepalive")) }} |
72 | 73 | location {{ .Path }} {
|
73 | 74 | {{- if eq .NetworkTag "internal" }}
|
74 | 75 | # Only allow traffic from internal clients
|
|
82 | 83 | root {{ trim .VhostRoot }};
|
83 | 84 | include fastcgi_params;
|
84 | 85 | fastcgi_pass {{ trim .Upstream }};
|
| 86 | + {{- if $keepalive }} |
| 87 | + fastcgi_keep_conn on; |
| 88 | + {{- end }} |
85 | 89 | {{- else if eq .Proto "grpc" }}
|
86 | 90 | grpc_pass {{ trim .Proto }}://{{ trim .Upstream }};
|
87 | 91 | {{- else }}
|
88 | 92 | proxy_pass {{ trim .Proto }}://{{ trim .Upstream }}{{ trim .Dest }};
|
| 93 | + {{- if $keepalive }} |
| 94 | + proxy_set_header Connection $proxy_connection_noclose; |
| 95 | + {{- end }} |
89 | 96 | {{- end }}
|
90 | 97 |
|
91 | 98 | {{- if (exists (printf "/etc/nginx/htpasswd/%s" .Host)) }}
|
@@ -161,6 +168,10 @@ upstream {{ .Upstream }} {
|
161 | 168 | # Fallback entry
|
162 | 169 | server 127.0.0.1 down;
|
163 | 170 | {{- end }}
|
| 171 | + {{- $keepalive := first (keys (groupByLabel .Containers "com.github.nginx-proxy.nginx-proxy.keepalive")) }} |
| 172 | + {{- if $keepalive }} |
| 173 | + keepalive {{ $keepalive }}; |
| 174 | + {{- end }} |
164 | 175 | }
|
165 | 176 | {{- end }}
|
166 | 177 |
|
@@ -193,6 +204,12 @@ map $http_upgrade $proxy_connection {
|
193 | 204 | default upgrade;
|
194 | 205 | '' close;
|
195 | 206 | }
|
| 207 | +map $http_upgrade $proxy_connection_noclose { |
| 208 | + default upgrade; |
| 209 | + # By default, nginx sets "Connection: close". Cancel that to allow keepalive |
| 210 | + # connections between nginx and the upstream server. |
| 211 | + '' ''; |
| 212 | +} |
196 | 213 |
|
197 | 214 | # Apply fix for very long server names
|
198 | 215 | server_names_hash_bucket_size 128;
|
@@ -450,7 +467,7 @@ server {
|
450 | 467 | {{- $upstream = printf "%s-%s" $upstream $sum }}
|
451 | 468 | {{- $dest = (or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "") }}
|
452 | 469 | {{- end }}
|
453 |
| - {{- template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }} |
| 470 | + {{- template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag "Containers" $containers) }} |
454 | 471 | {{- end }}
|
455 | 472 | {{- if and (not (contains $paths "/")) (ne $globals.default_root_response "none")}}
|
456 | 473 | location / {
|
|
0 commit comments