From 11d6faae707f6b57dc4db3425f4ed78d4285b1ba Mon Sep 17 00:00:00 2001 From: Jan Kremer Date: Fri, 27 Mar 2026 07:19:52 +0100 Subject: [PATCH] Handle 404 in Caddy --- modules/nixos/matrix.nix | 36 ++++++++++++++++++---------------- modules/nixos/website.nix | 41 +++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/modules/nixos/matrix.nix b/modules/nixos/matrix.nix index 677859d..eb696d2 100644 --- a/modules/nixos/matrix.nix +++ b/modules/nixos/matrix.nix @@ -23,27 +23,29 @@ ## Matrix federation virtualHosts = { "jankremer.de:8448" = { - extraConfig = '' - reverse_proxy localhost:6167 - ''; + extraConfig = # caddyfile + '' + reverse_proxy localhost:6167 + ''; }; "jankremer.de" = { - extraConfig = '' - handle /_matrix/* { - reverse_proxy localhost:6167 - } + extraConfig = # caddyfile + '' + handle /_matrix/* { + reverse_proxy localhost:6167 + } - handle /.well-known/matrix/server { - header Content-Type application/json - respond `{"m.server": "jankremer.de:443"}` 200 - } + handle /.well-known/matrix/server { + header Content-Type application/json + respond `{"m.server": "jankremer.de:443"}` 200 + } - handle /.well-known/matrix/client { - header Content-Type application/json - header Access-Control-Allow-Origin * - respond `{"m.homeserver": {"base_url": "https://jankremer.de"}}` 200 - } - ''; + handle /.well-known/matrix/client { + header Content-Type application/json + header Access-Control-Allow-Origin * + respond `{"m.homeserver": {"base_url": "https://jankremer.de"}}` 200 + } + ''; }; }; }; diff --git a/modules/nixos/website.nix b/modules/nixos/website.nix index e541f15..37bd1b2 100644 --- a/modules/nixos/website.nix +++ b/modules/nixos/website.nix @@ -4,26 +4,33 @@ ]; services.caddy.virtualHosts = { - "jankremer.de".extraConfig = '' - handle { - root * /var/www/jankremer.de - file_server + "jankremer.de".extraConfig = # caddyfile + '' + handle { + root * /var/www/jankremer.de + file_server - @static { - path *.css *.js *.woff2 *.woff *.ttf *.png *.jpg *.jpeg *.svg *.ico *.webp + @static { + path *.css *.js *.woff2 *.woff *.ttf *.png *.jpg *.jpeg *.svg *.ico *.webp + } + header @static Cache-Control "public, max-age=31536000, immutable" + + @html { + path *.html + } + header @html Cache-Control "no-cache" + + handle_errors { + rewrite * /404.html + file_server + } } - header @static Cache-Control "public, max-age=31536000, immutable" + ''; - @html { - path *.html - } - header @html Cache-Control "no-cache" - } - ''; - - "jankremer.eu".extraConfig = '' - redir https://jankremer.de{uri} permanent - ''; + "jankremer.eu".extraConfig = # caddyfile + '' + redir https://jankremer.de{uri} permanent + ''; }; networking.firewall.allowedTCPPorts = [