diff options
author | Alexander Bantyev <balsoft@balsoft.ru> | 2022-11-27 18:51:09 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 18:51:09 +0400 |
commit | df85dda331359fa8d8dd824195c48ac7432e24dd (patch) | |
tree | 74e1d20c7bb258d055c7ca208dfcc4891e93dbfc /nixos/modules/services/web-servers/nginx/default.nix | |
parent | 48769accd497d02590685d7054c660ce60693497 (diff) | |
parent | c09fd120cc056a324559aa8fcc9184968c9d0713 (diff) | |
download | nixlib-df85dda331359fa8d8dd824195c48ac7432e24dd.tar nixlib-df85dda331359fa8d8dd824195c48ac7432e24dd.tar.gz nixlib-df85dda331359fa8d8dd824195c48ac7432e24dd.tar.bz2 nixlib-df85dda331359fa8d8dd824195c48ac7432e24dd.tar.lz nixlib-df85dda331359fa8d8dd824195c48ac7432e24dd.tar.xz nixlib-df85dda331359fa8d8dd824195c48ac7432e24dd.tar.zst nixlib-df85dda331359fa8d8dd824195c48ac7432e24dd.zip |
Merge pull request #198314 from Izorkin/update-nginx-cache
nixos/nginx: add proxyCache options
Diffstat (limited to 'nixos/modules/services/web-servers/nginx/default.nix')
-rw-r--r-- | nixos/modules/services/web-servers/nginx/default.nix | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix index 12afc23592ba..85c76ed59d66 100644 --- a/nixos/modules/services/web-servers/nginx/default.nix +++ b/nixos/modules/services/web-servers/nginx/default.nix @@ -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} @@ -707,6 +715,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 = { |