nixos/nginx: add proxyCache options

This commit is contained in:
Izorkin 2022-10-28 19:42:35 +03:00
parent 544c526393
commit c09fd120cc
No known key found for this signature in database
GPG Key ID: 1436C1B3F3679F09

View File

@ -192,6 +192,14 @@ let
server_tokens ${if cfg.serverTokens then "on" else "off"};
${optionalString (cfg.proxyCache.enable) ''
proxy_cache_path /var/cache/nginx keys_zone=${cfg.proxyCache.keysZoneName}:${cfg.proxyCache.keysZoneSize}
levels=${cfg.proxyCache.levels}
use_temp_path=${if cfg.proxyCache.useTempPath then "on" else "off"}
inactive=${cfg.proxyCache.inactive}
max_size=${cfg.proxyCache.maxSize};
''}
${cfg.commonHttpConfig}
${vhosts}
@ -689,6 +697,72 @@ in
'';
};
proxyCache = mkOption {
type = types.submodule {
options = {
enable = mkEnableOption (lib.mdDoc "Enable proxy cache");
keysZoneName = mkOption {
type = types.str;
default = "cache";
example = "my_cache";
description = lib.mdDoc "Set name to shared memory zone.";
};
keysZoneSize = mkOption {
type = types.str;
default = "10m";
example = "32m";
description = lib.mdDoc "Set size to shared memory zone.";
};
levels = mkOption {
type = types.str;
default = "1:2";
example = "1:2:2";
description = lib.mdDoc ''
The levels parameter defines structure of subdirectories in cache: from
1 to 3, each level accepts values 1 or 2. Сan be used any combination of
1 and 2 in these formats: x, x:x and x:x:x.
'';
};
useTempPath = mkOption {
type = types.bool;
default = false;
example = true;
description = lib.mdDoc ''
Nginx first writes files that are destined for the cache to a temporary
storage area, and the use_temp_path=off directive instructs Nginx to
write them to the same directories where they will be cached. Recommended
that you set this parameter to off to avoid unnecessary copying of data
between file systems.
'';
};
inactive = mkOption {
type = types.str;
default = "10m";
example = "1d";
description = lib.mdDoc ''
Cached data that has not been accessed for the time specified by
the inactive parameter is removed from the cache, regardless of
its freshness.
'';
};
maxSize = mkOption {
type = types.str;
default = "1g";
example = "2048m";
description = lib.mdDoc "Set maximum cache size";
};
};
};
default = {};
description = lib.mdDoc "Configure proxy cache";
};
resolver = mkOption {
type = types.submodule {
options = {