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