Merge pull request #198314 from Izorkin/update-nginx-cache

nixos/nginx: add proxyCache options
This commit is contained in:
Alexander Bantyev 2022-11-27 18:51:09 +04:00 committed by GitHub
commit df85dda331
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 5 deletions

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}
@ -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 = {

View File

@ -79,11 +79,11 @@ stdenv.mkDerivation {
"--http-log-path=/var/log/nginx/access.log"
"--error-log-path=/var/log/nginx/error.log"
"--pid-path=/var/log/nginx/nginx.pid"
"--http-client-body-temp-path=/var/cache/nginx/client_body"
"--http-proxy-temp-path=/var/cache/nginx/proxy"
"--http-fastcgi-temp-path=/var/cache/nginx/fastcgi"
"--http-uwsgi-temp-path=/var/cache/nginx/uwsgi"
"--http-scgi-temp-path=/var/cache/nginx/scgi"
"--http-client-body-temp-path=/tmp/nginx_client_body"
"--http-proxy-temp-path=/tmp/nginx_proxy"
"--http-fastcgi-temp-path=/tmp/nginx_fastcgi"
"--http-uwsgi-temp-path=/tmp/nginx_uwsgi"
"--http-scgi-temp-path=/tmp/nginx_scgi"
] ++ optionals withDebug [
"--with-debug"
] ++ optionals withKTLS [