diff options
author | Izorkin <izorkin@elven.pw> | 2023-03-26 20:08:31 +0300 |
---|---|---|
committer | Izorkin <izorkin@elven.pw> | 2023-04-01 13:55:56 +0300 |
commit | 8a289bcc79950439935b830eaf7f1a533f124254 (patch) | |
tree | 804667f0be1cb5d22c1522ef3f43c46c1aa62aee /nixos/modules/services/web-servers/nginx/default.nix | |
parent | 9448487d9f7056253ecadfdab7d7bdc638191de2 (diff) | |
download | nixlib-8a289bcc79950439935b830eaf7f1a533f124254.tar nixlib-8a289bcc79950439935b830eaf7f1a533f124254.tar.gz nixlib-8a289bcc79950439935b830eaf7f1a533f124254.tar.bz2 nixlib-8a289bcc79950439935b830eaf7f1a533f124254.tar.lz nixlib-8a289bcc79950439935b830eaf7f1a533f124254.tar.xz nixlib-8a289bcc79950439935b830eaf7f1a533f124254.tar.zst nixlib-8a289bcc79950439935b830eaf7f1a533f124254.zip |
nixos/nginx: enable multiple proxyCachePath support
Diffstat (limited to 'nixos/modules/services/web-servers/nginx/default.nix')
-rw-r--r-- | nixos/modules/services/web-servers/nginx/default.nix | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix index 064c86a9a7e2..e61e11d73087 100644 --- a/nixos/modules/services/web-servers/nginx/default.nix +++ b/nixos/modules/services/web-servers/nginx/default.nix @@ -102,6 +102,17 @@ let 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: '' upstream ${name} { ${toString (flip mapAttrsToList upstream.servers (name: server: '' @@ -240,16 +251,10 @@ 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} + ${proxyCachePathConfig} + ${vhosts} ${optionalString cfg.statusPage '' @@ -796,10 +801,10 @@ in ''; }; - proxyCache = mkOption { - type = types.submodule { + proxyCachePath = mkOption { + type = types.attrsOf (types.submodule ({ ... }: { options = { - enable = mkEnableOption (lib.mdDoc "Enable proxy cache"); + enable = mkEnableOption (lib.mdDoc "this proxy cache path entry"); keysZoneName = mkOption { type = types.str; @@ -857,9 +862,12 @@ in description = lib.mdDoc "Set maximum cache size"; }; }; - }; + })); 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 { @@ -970,6 +978,12 @@ in 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. '') + (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 { |