From 6511fa9f589920725f9cf76d024445d52ecdbf54 Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Fri, 14 Sep 2018 19:40:54 -0400 Subject: [PATCH] make upstream keepalive work for http --- rootfs/etc/nginx/template/nginx.tmpl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 79b5f24de..c947dc0ea 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -244,16 +244,15 @@ http { {{ buildResolvers $cfg.Resolver $cfg.DisableIpv6DNS }} - {{/* Whenever nginx proxies a request without a "Connection" header, the "Connection" header is set to "close" */}} - {{/* when making the target request. This means that you cannot simply use */}} - {{/* "proxy_set_header Connection $http_connection" for WebSocket support because in this case, the */}} - {{/* "Connection" header would be set to "" whenever the original request did not have a "Connection" header, */}} - {{/* which would mean no "Connection" header would be in the target request. Since this would deviate from */}} - {{/* normal nginx behavior we have to use this approach. */}} - # Retain the default nginx handling of requests without a "Connection" header + # See https://www.nginx.com/blog/websocket-nginx map $http_upgrade $connection_upgrade { default upgrade; + {{ if (gt $cfg.UpstreamKeepaliveConnections 0) }} + # See http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive + '' ''; + {{ else }} '' close; + {{ end }} } # The following is a sneaky way to do "set $the_real_ip $remote_addr"