1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-30 19:47:47 +00:00

fix: redirect to root domain for 404's

This commit is contained in:
RGBCube 2025-02-23 20:28:39 +03:00
parent 5609e12668
commit f3e93ee63e
3 changed files with 20 additions and 56 deletions

View file

@ -2,54 +2,31 @@
inherit (config.networking) domain;
inherit (lib) enabled merge;
pathSite = "/var/www/site";
configNotFoundLocation = {
extraConfig = /* nginx */ ''
error_page 404 /404.html;
'';
locations."/404".extraConfig = /* nginx */ ''
internal;
'';
};
root = "/var/www/site";
in {
imports = [(self + /modules/nginx.nix)];
services.nginx = enabled {
virtualHosts.${domain} = merge config.services.nginx.sslTemplate configNotFoundLocation {
root = pathSite;
virtualHosts.${domain} = merge config.services.nginx.sslTemplate {
inherit root;
locations."/".tryFiles = "$uri $uri.html $uri/index.html =404";
locations."/assets/".extraConfig = /* nginx */ ''
if ($request_method = OPTIONS) {
${config.services.nginx.headers}
add_header Content-Type text/plain always;
add_header Content-Length 0 always;
return 204;
}
extraConfig = /* nginx */ ''
error_page 404 /404.html;
'';
expires 24h;
locations."/404".extraConfig = /* nginx */ ''
internal;
'';
};
virtualHosts."www.${domain}" = merge config.services.nginx.sslTemplate {
locations."/".extraConfig = /* nginx */ ''
return 301 https://${domain}$request_uri;
'';
locations."/".return = "301 https://${domain}$request_uri";
};
virtualHosts._ = merge config.services.nginx.sslTemplate configNotFoundLocation {
root = pathSite;
locations."/".extraConfig = /* nginx */ ''
return 404;
'';
locations."/assets/".extraConfig = /* nginx */ ''
return 301 https://${domain}$request_uri;
'';
virtualHosts._ = merge config.services.nginx.sslTemplate {
locations."/".return = "301 https://${domain}/404";
};
};
}