From eab1ffbdf58a020e9bad8d00c4f13e62761a8ebb Mon Sep 17 00:00:00 2001 From: thefosk Date: Thu, 17 Nov 2016 18:22:41 -0800 Subject: [PATCH] keep-alive by default, unless it is an Upgrade request --- kong/core/handler.lua | 4 ++++ kong/templates/nginx_kong.lua | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kong/core/handler.lua b/kong/core/handler.lua index 7a4372723e6..bbb6c791c6f 100644 --- a/kong/core/handler.lua +++ b/kong/core/handler.lua @@ -60,6 +60,10 @@ return { ngx.log(ngx.ERR, "failed the initial dns/balancer resolve: ", err) return responses.send_HTTP_INTERNAL_SERVER_ERROR() end + + -- Websocket + local is_upgrade = ngx.var.http_connection and ngx.var.http_connection:lower() == "upgrade" + ngx.var.upstream_connection = is_upgrade and "upgrade" or "keep-alive" end, -- Only executed if the `resolver` module found an API and allows nginx to proxy it. after = function() diff --git a/kong/templates/nginx_kong.lua b/kong/templates/nginx_kong.lua index 9fc9f50022f..e7003942d06 100644 --- a/kong/templates/nginx_kong.lua +++ b/kong/templates/nginx_kong.lua @@ -63,11 +63,6 @@ upstream kong_upstream { keepalive ${{UPSTREAM_KEEPALIVE}}; } -map $http_upgrade $connection_upgrade { - default upgrade; - '' close; -} - server { server_name kong; listen ${{PROXY_LISTEN}}; @@ -89,6 +84,7 @@ server { location / { set $upstream_host nil; set $upstream_url nil; + set $upstream_connection nil; access_by_lua_block { kong.access() @@ -100,7 +96,7 @@ server { proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $upstream_host; proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; + proxy_set_header Connection $upstream_connection; proxy_pass_header Server; proxy_pass $upstream_url;