diff options
author | Robin Gloster <mail@glob.in> | 2017-04-15 17:53:46 +0200 |
---|---|---|
committer | Robin Gloster <mail@glob.in> | 2017-08-30 21:01:53 +0200 |
commit | 4ffa9ddb30726808416ecb26a4389b1d2ac6337e (patch) | |
tree | f4eef4cd8a60dd48f662cbe2a2743fa1fd070959 /nixos/modules/services/web-servers | |
parent | 759daba9801af7cceb62674488129c223dc22f70 (diff) | |
download | nixlib-4ffa9ddb30726808416ecb26a4389b1d2ac6337e.tar nixlib-4ffa9ddb30726808416ecb26a4389b1d2ac6337e.tar.gz nixlib-4ffa9ddb30726808416ecb26a4389b1d2ac6337e.tar.bz2 nixlib-4ffa9ddb30726808416ecb26a4389b1d2ac6337e.tar.lz nixlib-4ffa9ddb30726808416ecb26a4389b1d2ac6337e.tar.xz nixlib-4ffa9ddb30726808416ecb26a4389b1d2ac6337e.tar.zst nixlib-4ffa9ddb30726808416ecb26a4389b1d2ac6337e.zip |
nginx module: allow basic configuration of upstreams
Diffstat (limited to 'nixos/modules/services/web-servers')
-rw-r--r-- | nixos/modules/services/web-servers/nginx/default.nix | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix index 93339c075cad..249b660d8c68 100644 --- a/nixos/modules/services/web-servers/nginx/default.nix +++ b/nixos/modules/services/web-servers/nginx/default.nix @@ -29,6 +29,14 @@ let proxy_set_header Accept-Encoding ""; ''; + upstreamConfig = toString (flip mapAttrsToList cfg.upstreams (name: upstream: '' + upstream ${name} { + ${toString (flip mapAttrsToList upstream.servers (name: server: '' + server ${name} ${optionalString server.backup "backup"}; + ''))} + } + '')); + configFile = pkgs.writeText "nginx.conf" '' user ${cfg.user} ${cfg.group}; error_log stderr; @@ -51,6 +59,7 @@ let ${optionalString (cfg.resolver.addresses != []) '' resolver ${toString cfg.resolver.addresses} ${optionalString (cfg.resolver.valid != "") "valid=${cfg.resolver.valid}"}; ''} + ${upstreamConfig} ${optionalString (cfg.recommendedOptimisation) '' # optimisation @@ -443,6 +452,35 @@ in default = {}; }; + upstreams = mkOption { + type = types.attrsOf (types.submodule { + options = { + servers = mkOption { + type = types.attrsOf (types.submodule { + options = { + backup = mkOption { + type = types.bool; + default = false; + description = '' + Marks the server as a backup server. It will be passed + requests when the primary servers are unavailable. + ''; + }; + }; + }); + description = '' + Defines the address and other parameters of the upstream servers. + ''; + default = {}; + }; + }; + }); + description = '' + Defines a group of servers to use as proxy target. + ''; + default = {}; + }; + virtualHosts = mkOption { type = types.attrsOf (types.submodule (import ./vhost-options.nix { inherit config lib; |