nixos/caddy: Fix default log file for http:// hostnames (#371802)

authored by Donovan Glover and committed by GitHub 24a8c64c 24a2206e

+15 -2
+1 -1
nixos/modules/services/web-servers/caddy/vhost-options.nix
··· 58 logFormat = mkOption { 59 type = types.lines; 60 default = '' 61 - output file ${cfg.logDir}/access-${config.hostName}.log 62 ''; 63 defaultText = '' 64 output file ''${config.services.caddy.logDir}/access-''${hostName}.log
··· 58 logFormat = mkOption { 59 type = types.lines; 60 default = '' 61 + output file ${cfg.logDir}/access-${lib.replaceStrings [ "/" " " ] [ "_" "_" ] config.hostName}.log 62 ''; 63 defaultText = '' 64 output file ''${config.services.caddy.logDir}/access-''${hostName}.log
+14 -1
nixos/tests/caddy.nix
··· 41 "http://localhost:8081" = { }; 42 }; 43 }; 44 specialisation.rfc42.configuration = { 45 services.caddy.settings = { 46 apps.http.servers.default = { ··· 70 services.caddy = { 71 package = pkgs.caddy.withPlugins { 72 plugins = [ "github.com/caddyserver/replace-response@v0.0.0-20241211194404-3865845790a7" ]; 73 - hash = "sha256-zgMdtOJbmtRSfTlrrg8njr11in2C7OAXLB+34V23jek="; 74 }; 75 configFile = pkgs.writeText "Caddyfile" '' 76 { ··· 93 explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file"; 94 justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload"; 95 multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs"; 96 rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42"; 97 withPluginsConfig = "${nodes.webserver.system.build.toplevel}/specialisation/with-plugins"; 98 in ··· 113 with subtest("multiple configs are correctly merged"): 114 webserver.succeed( 115 "${multipleConfigs}/bin/switch-to-configuration test >&2" 116 ) 117 webserver.wait_for_open_port(8080) 118 webserver.wait_for_open_port(8081)
··· 41 "http://localhost:8081" = { }; 42 }; 43 }; 44 + specialisation.multiple-hostnames.configuration = { 45 + services.caddy.virtualHosts = { 46 + "http://localhost:8080 http://localhost:8081" = { }; 47 + }; 48 + }; 49 specialisation.rfc42.configuration = { 50 services.caddy.settings = { 51 apps.http.servers.default = { ··· 75 services.caddy = { 76 package = pkgs.caddy.withPlugins { 77 plugins = [ "github.com/caddyserver/replace-response@v0.0.0-20241211194404-3865845790a7" ]; 78 + hash = "sha256-BorJJWICgAWU7DrpDZJWifMnIYtGWldt/4S1VELwGJI="; 79 }; 80 configFile = pkgs.writeText "Caddyfile" '' 81 { ··· 98 explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file"; 99 justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload"; 100 multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs"; 101 + multipleHostnames = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-hostnames"; 102 rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42"; 103 withPluginsConfig = "${nodes.webserver.system.build.toplevel}/specialisation/with-plugins"; 104 in ··· 119 with subtest("multiple configs are correctly merged"): 120 webserver.succeed( 121 "${multipleConfigs}/bin/switch-to-configuration test >&2" 122 + ) 123 + webserver.wait_for_open_port(8080) 124 + webserver.wait_for_open_port(8081) 125 + 126 + with subtest("a virtual host with multiple hostnames works"): 127 + webserver.succeed( 128 + "${multipleHostnames}/bin/switch-to-configuration test >&2" 129 ) 130 webserver.wait_for_open_port(8080) 131 webserver.wait_for_open_port(8081)