Merge pull request #224688 from Izorkin/add-nginx-upstream-timeout
nixos/nginx: allow arbitrary parameters in upstream servers
This commit is contained in:
commit
0767f800e0
1 changed files with 25 additions and 8 deletions
|
@ -113,10 +113,15 @@ let
|
||||||
]};
|
]};
|
||||||
'') (filterAttrs (name: conf: conf.enable) cfg.proxyCachePath));
|
'') (filterAttrs (name: conf: conf.enable) cfg.proxyCachePath));
|
||||||
|
|
||||||
|
toUpstreamParameter = key: value:
|
||||||
|
if builtins.isBool value
|
||||||
|
then lib.optionalString value key
|
||||||
|
else "${key}=${toString value}";
|
||||||
|
|
||||||
upstreamConfig = toString (flip mapAttrsToList cfg.upstreams (name: upstream: ''
|
upstreamConfig = toString (flip mapAttrsToList cfg.upstreams (name: upstream: ''
|
||||||
upstream ${name} {
|
upstream ${name} {
|
||||||
${toString (flip mapAttrsToList upstream.servers (name: server: ''
|
${toString (flip mapAttrsToList upstream.servers (name: server: ''
|
||||||
server ${name} ${optionalString server.backup "backup"};
|
server ${name} ${concatStringsSep " " (mapAttrsToList toUpstreamParameter server)};
|
||||||
''))}
|
''))}
|
||||||
${upstream.extraConfig}
|
${upstream.extraConfig}
|
||||||
}
|
}
|
||||||
|
@ -922,6 +927,7 @@ in
|
||||||
options = {
|
options = {
|
||||||
servers = mkOption {
|
servers = mkOption {
|
||||||
type = types.attrsOf (types.submodule {
|
type = types.attrsOf (types.submodule {
|
||||||
|
freeformType = types.attrsOf (types.oneOf [ types.bool types.int types.str ]);
|
||||||
options = {
|
options = {
|
||||||
backup = mkOption {
|
backup = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
@ -935,9 +941,11 @@ in
|
||||||
});
|
});
|
||||||
description = lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
Defines the address and other parameters of the upstream servers.
|
Defines the address and other parameters of the upstream servers.
|
||||||
|
See [the documentation](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
|
||||||
|
for the available parameters.
|
||||||
'';
|
'';
|
||||||
default = {};
|
default = {};
|
||||||
example = { "127.0.0.1:8000" = {}; };
|
example = lib.literalMD "see [](#opt-services.nginx.upstreams)";
|
||||||
};
|
};
|
||||||
extraConfig = mkOption {
|
extraConfig = mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
|
@ -952,14 +960,23 @@ in
|
||||||
Defines a group of servers to use as proxy target.
|
Defines a group of servers to use as proxy target.
|
||||||
'';
|
'';
|
||||||
default = {};
|
default = {};
|
||||||
example = literalExpression ''
|
example = {
|
||||||
"backend_server" = {
|
"backend" = {
|
||||||
servers = { "127.0.0.1:8000" = {}; };
|
servers = {
|
||||||
extraConfig = ''''
|
"backend1.example.com:8080" = { weight = 5; };
|
||||||
|
"backend2.example.com" = { max_fails = 3; fail_timeout = "30s"; };
|
||||||
|
"backend3.example.com" = {};
|
||||||
|
"backup1.example.com" = { backup = true; };
|
||||||
|
"backup2.example.com" = { backup = true; };
|
||||||
|
};
|
||||||
|
extraConfig = ''
|
||||||
keepalive 16;
|
keepalive 16;
|
||||||
'''';
|
'';
|
||||||
};
|
};
|
||||||
'';
|
"memcached" = {
|
||||||
|
servers."unix:/run//memcached/memcached.sock" = {};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
virtualHosts = mkOption {
|
virtualHosts = mkOption {
|
||||||
|
|
Loading…
Reference in a new issue