nixos/nginx: add option typesHashMaxSize (#341072)

authored by Franz Pletz and committed by GitHub e1635a35 77cfc584

+45 -5
+15 -5
nixos/modules/services/web-servers/nginx/default.nix
··· 129 129 '')); 130 130 131 131 commonHttpConfig = '' 132 - # Load mime types. 132 + # Load mime types and configure maximum size of the types hash tables. 133 133 include ${cfg.defaultMimeTypes}; 134 - # When recommendedOptimisation is disabled nginx fails to start because the mailmap mime.types database 135 - # contains 1026 entries and the default is only 1024. Setting to a higher number to remove the need to 136 - # overwrite it because nginx does not allow duplicated settings. 137 - types_hash_max_size 4096; 134 + types_hash_max_size ${toString cfg.typesHashMaxSize}; 138 135 139 136 include ${cfg.package}/conf/fastcgi.conf; 140 137 include ${cfg.package}/conf/uwsgi_params; ··· 894 891 description = '' 895 892 Sets the maximum size of the server names hash tables. 896 893 ''; 894 + }; 895 + 896 + typesHashMaxSize = mkOption { 897 + type = types.ints.positive; 898 + default = if cfg.defaultMimeTypes == "${pkgs.mailcap}/etc/nginx/mime.types" then 2688 else 1024; 899 + defaultText = literalExpression ''if cfg.defaultMimeTypes == "''${pkgs.mailcap}/etc/nginx/mime.types" then 2688 else 1024''; 900 + description = '' 901 + Sets the maximum size of the types hash tables (`types_hash_max_size`). 902 + It is recommended that the minimum size possible size is used. 903 + If {option}`recommendedOptimisation` is disabled, nginx would otherwise 904 + fail to start since the mailmap `mime.types` database has more entries 905 + than the nginx default value 1024. 906 + ''; 897 907 }; 898 908 899 909 proxyCachePath = mkOption {
+1
nixos/tests/all-tests.nix
··· 670 670 nginx-etag-compression = handleTest ./nginx-etag-compression.nix {}; 671 671 nginx-globalredirect = handleTest ./nginx-globalredirect.nix {}; 672 672 nginx-http3 = handleTest ./nginx-http3.nix {}; 673 + nginx-mime = handleTest ./nginx-mime.nix {}; 673 674 nginx-modsecurity = handleTest ./nginx-modsecurity.nix {}; 674 675 nginx-moreheaders = handleTest ./nginx-moreheaders.nix {}; 675 676 nginx-njs = handleTest ./nginx-njs.nix {};
+26
nixos/tests/nginx-mime.nix
··· 1 + import ./make-test-python.nix ( 2 + { lib, pkgs, ... }: 3 + { 4 + name = "nginx-mime"; 5 + meta.maintainers = with pkgs.lib.maintainers; [ izorkin ]; 6 + 7 + nodes = { 8 + server = 9 + { pkgs, ... }: 10 + { 11 + services.nginx = { 12 + enable = true; 13 + virtualHosts."localhost" = { }; 14 + }; 15 + }; 16 + }; 17 + 18 + testScript = '' 19 + server.start() 20 + server.wait_for_unit("nginx") 21 + # Check optimal size of types_hash 22 + server.fail("journalctl --unit nginx --grep 'could not build optimal types_hash'") 23 + server.shutdown() 24 + ''; 25 + } 26 + )
+3
pkgs/data/misc/mailcap/default.nix
··· 1 1 { lib 2 2 , stdenv 3 3 , fetchurl 4 + , nixosTests 4 5 5 6 # updater 6 7 , git ··· 43 44 head -n1)" 44 45 exec nix-update --version "$VERSION" "$@" 45 46 ''; 47 + 48 + passthru.tests.nginx-mime = nixosTests.nginx-mime; 46 49 47 50 meta = with lib; { 48 51 description = "Helper application and MIME type associations for file types";