nginx module: add option for proxying websocket requests

This commit is contained in:
Franz Pletz 2017-02-11 04:11:35 +01:00 committed by Robin Gloster
parent 530282eebe
commit 65c2203ffc
No known key found for this signature in database
GPG Key ID: D5C458DF6DD97EDF
2 changed files with 19 additions and 0 deletions

View File

@ -92,6 +92,11 @@ let
include ${recommendedProxyConfig};
''}
# $connection_upgrade is used for websocket proxying
map $http_upgrade $connection_upgrade {
default upgrade;
''' close;
}
client_max_body_size ${cfg.clientMaxBodySize};
server_tokens ${if cfg.serverTokens then "on" else "off"};
@ -213,6 +218,11 @@ let
proxy_pass ${config.proxyPass};
${optionalString cfg.recommendedProxySettings "include ${recommendedProxyConfig};"}
''}
${optionalString config.proxyWebsockets ''
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
''}
${optionalString (config.index != null) "index ${config.index};"}
${optionalString (config.tryFiles != null) "try_files ${config.tryFiles};"}
${optionalString (config.root != null) "root ${config.root};"}

View File

@ -19,6 +19,15 @@ with lib;
'';
};
proxyWebsockets = mkOption {
type = types.bool;
default = false;
example = true;
description = ''
Whether to supporty proxying websocket connections with HTTP/1.1.
'';
};
index = mkOption {
type = types.nullOr types.str;
default = null;