mirror of
https://github.com/RGBCube/ncc
synced 2025-07-28 02:27:44 +00:00
fix: redirect to root domain for 404's
This commit is contained in:
parent
5609e12668
commit
f3e93ee63e
3 changed files with 20 additions and 56 deletions
|
@ -69,6 +69,13 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
services.nginx.virtualHosts.${fqdn} = merge config.services.nginx.sslTemplate {
|
services.nginx.virtualHosts.${fqdn} = merge config.services.nginx.sslTemplate {
|
||||||
|
extraConfig = /* nginx */ ''
|
||||||
|
# Grafana sets `nosniff` while not setting the content type properly,
|
||||||
|
# so everything breaks with it. Unset the header.
|
||||||
|
${config.services.nginx.headers}
|
||||||
|
add_header X-Content-Type-Options "" always;
|
||||||
|
'';
|
||||||
|
|
||||||
locations."/" = {
|
locations."/" = {
|
||||||
proxyPass = "http://[::1]:${toString port}";
|
proxyPass = "http://[::1]:${toString port}";
|
||||||
proxyWebsockets = true;
|
proxyWebsockets = true;
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
inherit (config.networking) domain;
|
inherit (config.networking) domain;
|
||||||
inherit (lib) const enabled genAttrs merge strings;
|
inherit (lib) const enabled genAttrs merge strings;
|
||||||
|
|
||||||
pathSite = "/var/www/site";
|
|
||||||
|
|
||||||
fqdn = "chat.${domain}";
|
fqdn = "chat.${domain}";
|
||||||
port = 8002;
|
port = 8002;
|
||||||
|
|
||||||
|
@ -24,24 +22,6 @@
|
||||||
"m.server" = "${fqdn}:443";
|
"m.server" = "${fqdn}:443";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
configNotFoundLocation = {
|
|
||||||
extraConfig = /* nginx */ ''
|
|
||||||
error_page 404 /404.html;
|
|
||||||
'';
|
|
||||||
|
|
||||||
locations."/".extraConfig = /* nginx */ ''
|
|
||||||
return 404;
|
|
||||||
'';
|
|
||||||
|
|
||||||
locations."/404".extraConfig = /* nginx */ ''
|
|
||||||
internal;
|
|
||||||
'';
|
|
||||||
|
|
||||||
locations."/assets/".extraConfig = /* nginx */ ''
|
|
||||||
return 301 https://${domain}$request_uri;
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
in {
|
in {
|
||||||
imports = [(self + /modules/nginx.nix)];
|
imports = [(self + /modules/nginx.nix)];
|
||||||
|
|
||||||
|
@ -103,8 +83,8 @@ in {
|
||||||
|
|
||||||
services.nginx.virtualHosts.${domain} = configWellKnownResponse;
|
services.nginx.virtualHosts.${domain} = configWellKnownResponse;
|
||||||
|
|
||||||
services.nginx.virtualHosts.${fqdn} = merge config.services.nginx.sslTemplate configWellKnownResponse configNotFoundLocation {
|
services.nginx.virtualHosts.${fqdn} = merge config.services.nginx.sslTemplate configWellKnownResponse {
|
||||||
root = pathSite;
|
locations."/".return = "301 https://${domain}/404";
|
||||||
|
|
||||||
locations."/_matrix".proxyPass = "http://[::1]:${toString port}";
|
locations."/_matrix".proxyPass = "http://[::1]:${toString port}";
|
||||||
locations."/_synapse/client".proxyPass = "http://[::1]:${toString port}";
|
locations."/_synapse/client".proxyPass = "http://[::1]:${toString port}";
|
||||||
|
|
|
@ -2,54 +2,31 @@
|
||||||
inherit (config.networking) domain;
|
inherit (config.networking) domain;
|
||||||
inherit (lib) enabled merge;
|
inherit (lib) enabled merge;
|
||||||
|
|
||||||
pathSite = "/var/www/site";
|
root = "/var/www/site";
|
||||||
|
|
||||||
configNotFoundLocation = {
|
|
||||||
extraConfig = /* nginx */ ''
|
|
||||||
error_page 404 /404.html;
|
|
||||||
'';
|
|
||||||
|
|
||||||
locations."/404".extraConfig = /* nginx */ ''
|
|
||||||
internal;
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
in {
|
in {
|
||||||
imports = [(self + /modules/nginx.nix)];
|
imports = [(self + /modules/nginx.nix)];
|
||||||
|
|
||||||
services.nginx = enabled {
|
services.nginx = enabled {
|
||||||
virtualHosts.${domain} = merge config.services.nginx.sslTemplate configNotFoundLocation {
|
virtualHosts.${domain} = merge config.services.nginx.sslTemplate {
|
||||||
root = pathSite;
|
inherit root;
|
||||||
|
|
||||||
locations."/".tryFiles = "$uri $uri.html $uri/index.html =404";
|
locations."/".tryFiles = "$uri $uri.html $uri/index.html =404";
|
||||||
|
|
||||||
locations."/assets/".extraConfig = /* nginx */ ''
|
extraConfig = /* nginx */ ''
|
||||||
if ($request_method = OPTIONS) {
|
error_page 404 /404.html;
|
||||||
${config.services.nginx.headers}
|
'';
|
||||||
add_header Content-Type text/plain always;
|
|
||||||
add_header Content-Length 0 always;
|
|
||||||
return 204;
|
|
||||||
}
|
|
||||||
|
|
||||||
expires 24h;
|
locations."/404".extraConfig = /* nginx */ ''
|
||||||
|
internal;
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
virtualHosts."www.${domain}" = merge config.services.nginx.sslTemplate {
|
virtualHosts."www.${domain}" = merge config.services.nginx.sslTemplate {
|
||||||
locations."/".extraConfig = /* nginx */ ''
|
locations."/".return = "301 https://${domain}$request_uri";
|
||||||
return 301 https://${domain}$request_uri;
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virtualHosts._ = merge config.services.nginx.sslTemplate configNotFoundLocation {
|
virtualHosts._ = merge config.services.nginx.sslTemplate {
|
||||||
root = pathSite;
|
locations."/".return = "301 https://${domain}/404";
|
||||||
|
|
||||||
locations."/".extraConfig = /* nginx */ ''
|
|
||||||
return 404;
|
|
||||||
'';
|
|
||||||
|
|
||||||
locations."/assets/".extraConfig = /* nginx */ ''
|
|
||||||
return 301 https://${domain}$request_uri;
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue