Merge pull request #223085 from Izorkin/update-nginx-proxy-cache
nixos/nginx: enable multiple proxyCachePath support
This commit is contained in:
commit
0e950a1ec7
2 changed files with 29 additions and 13 deletions
|
@ -321,6 +321,8 @@ In addition to numerous new and upgraded packages, this release has the followin
|
||||||
|
|
||||||
- Enabling global redirect in `services.nginx.virtualHosts` now allows one to add exceptions with the `locations` option.
|
- Enabling global redirect in `services.nginx.virtualHosts` now allows one to add exceptions with the `locations` option.
|
||||||
|
|
||||||
|
- A new option `proxyCachePath` has been added to `services.nginx`. Learn more about proxy_cache_path: <https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path>.
|
||||||
|
|
||||||
- A new option `recommendedBrotliSettings` has been added to `services.nginx`. Learn more about compression in Brotli format [here](https://github.com/google/ngx_brotli/blob/master/README.md).
|
- A new option `recommendedBrotliSettings` has been added to `services.nginx`. Learn more about compression in Brotli format [here](https://github.com/google/ngx_brotli/blob/master/README.md).
|
||||||
|
|
||||||
- Updated recommended settings in `services.nginx.recommendedGzipSettings`:
|
- Updated recommended settings in `services.nginx.recommendedGzipSettings`:
|
||||||
|
|
|
@ -102,6 +102,17 @@ let
|
||||||
proxy_set_header X-Forwarded-Server $host;
|
proxy_set_header X-Forwarded-Server $host;
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
proxyCachePathConfig = concatStringsSep "\n" (mapAttrsToList (name: proxyCachePath: ''
|
||||||
|
proxy_cache_path ${concatStringsSep " " [
|
||||||
|
"/var/cache/nginx/${name}"
|
||||||
|
"keys_zone=${proxyCachePath.keysZoneName}:${proxyCachePath.keysZoneSize}"
|
||||||
|
"levels=${proxyCachePath.levels}"
|
||||||
|
"use_temp_path=${if proxyCachePath.useTempPath then "on" else "off"}"
|
||||||
|
"inactive=${proxyCachePath.inactive}"
|
||||||
|
"max_size=${proxyCachePath.maxSize}"
|
||||||
|
]};
|
||||||
|
'') (filterAttrs (name: conf: conf.enable) cfg.proxyCachePath));
|
||||||
|
|
||||||
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: ''
|
||||||
|
@ -241,16 +252,10 @@ let
|
||||||
|
|
||||||
server_tokens ${if cfg.serverTokens then "on" else "off"};
|
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}
|
${cfg.commonHttpConfig}
|
||||||
|
|
||||||
|
${proxyCachePathConfig}
|
||||||
|
|
||||||
${vhosts}
|
${vhosts}
|
||||||
|
|
||||||
${optionalString cfg.statusPage ''
|
${optionalString cfg.statusPage ''
|
||||||
|
@ -808,10 +813,10 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
proxyCache = mkOption {
|
proxyCachePath = mkOption {
|
||||||
type = types.submodule {
|
type = types.attrsOf (types.submodule ({ ... }: {
|
||||||
options = {
|
options = {
|
||||||
enable = mkEnableOption (lib.mdDoc "Enable proxy cache");
|
enable = mkEnableOption (lib.mdDoc "this proxy cache path entry");
|
||||||
|
|
||||||
keysZoneName = mkOption {
|
keysZoneName = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
@ -869,9 +874,12 @@ in
|
||||||
description = lib.mdDoc "Set maximum cache size";
|
description = lib.mdDoc "Set maximum cache size";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
}));
|
||||||
default = {};
|
default = {};
|
||||||
description = lib.mdDoc "Configure proxy cache";
|
description = lib.mdDoc ''
|
||||||
|
Configure a proxy cache path entry.
|
||||||
|
See <http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path> for documentation.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
resolver = mkOption {
|
resolver = mkOption {
|
||||||
|
@ -982,6 +990,12 @@ in
|
||||||
The Nginx log directory has been moved to /var/log/nginx, the cache directory
|
The Nginx log directory has been moved to /var/log/nginx, the cache directory
|
||||||
to /var/cache/nginx. The option services.nginx.stateDir has been removed.
|
to /var/cache/nginx. The option services.nginx.stateDir has been removed.
|
||||||
'')
|
'')
|
||||||
|
(mkRenamedOptionModule [ "services" "nginx" "proxyCache" "inactive" ] [ "services" "nginx" "proxyCachePath" "" "inactive" ])
|
||||||
|
(mkRenamedOptionModule [ "services" "nginx" "proxyCache" "useTempPath" ] [ "services" "nginx" "proxyCachePath" "" "useTempPath" ])
|
||||||
|
(mkRenamedOptionModule [ "services" "nginx" "proxyCache" "levels" ] [ "services" "nginx" "proxyCachePath" "" "levels" ])
|
||||||
|
(mkRenamedOptionModule [ "services" "nginx" "proxyCache" "keysZoneSize" ] [ "services" "nginx" "proxyCachePath" "" "keysZoneSize" ])
|
||||||
|
(mkRenamedOptionModule [ "services" "nginx" "proxyCache" "keysZoneName" ] [ "services" "nginx" "proxyCachePath" "" "keysZoneName" ])
|
||||||
|
(mkRenamedOptionModule [ "services" "nginx" "proxyCache" "enable" ] [ "services" "nginx" "proxyCachePath" "" "enable" ])
|
||||||
];
|
];
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
Loading…
Reference in a new issue