nixos-config/nixos/programs/nginx.nix

149 lines
4.2 KiB
Nix
Raw Normal View History

2023-08-17 21:46:39 +05:00
{ config, ... }:
2023-08-19 12:06:57 +05:00
let
# Required stuff for synapse
clientConfig."m.homeserver".base_url = "https://matrix.comfycamp.space";
serverConfig."m.server" = "matrix.comfycamp.space:443";
mkWellKnown = data: ''
add_header Content-Type application/json;
add_header Access-Control-Allow-Origin *;
return 200 '${builtins.toJSON data}';
'';
in {
2023-08-17 21:46:39 +05:00
services.nginx = {
enable = true;
recommendedTlsSettings = true;
recommendedOptimisation = true;
recommendedGzipSettings = true;
recommendedProxySettings = true;
2023-08-18 18:26:54 +05:00
commonHttpConfig = ''
# Add HSTS header with preloading to HTTPS requests.
# Adding this header to HTTP requests is discouraged
map $scheme $hsts_header {
https "max-age=31536000; includeSubdomains; preload";
}
add_header Strict-Transport-Security $hsts_header;
'';
2023-08-17 21:46:39 +05:00
virtualHosts = {
2023-08-19 12:06:57 +05:00
"comfycamp.space" = {
useACMEHost = "comfycamp.space";
forceSSL = true;
# This section is not needed if the server_name of matrix-synapse is equal to
# the domain (i.e. example.org from @foo:example.org) and the federation port
# is 8448.
# Further reference can be found in the docs about delegation under
# https://matrix-org.github.io/synapse/latest/delegate.html
locations."= /.well-known/matrix/server".extraConfig = mkWellKnown serverConfig;
# This is usually needed for homeserver discovery (from e.g. other Matrix clients).
# Further reference can be found in the upstream docs at
# https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixclient
locations."= /.well-known/matrix/client".extraConfig = mkWellKnown clientConfig;
};
2023-08-19 19:41:37 +05:00
# Nextcloud
2023-08-18 18:22:03 +05:00
"nc.comfycamp.space" = {
useACMEHost = "comfycamp.space";
forceSSL = true;
};
2023-08-19 19:41:37 +05:00
# Jellyfin
2023-08-18 21:13:48 +05:00
"jf.comfycamp.space" = {
2023-08-18 21:20:26 +05:00
useACMEHost = "comfycamp.space";
forceSSL = true;
2023-08-18 21:13:48 +05:00
locations = {
"/" = {
proxyPass = "http://127.0.0.1:8096";
};
};
};
2023-08-19 19:41:37 +05:00
2023-08-19 20:27:34 +05:00
# Plausible
"plausible.comfycamp.space" = {
useACMEHost = "comfycamp.space";
forceSSL = true;
locations = {
"/" = {
proxyPass = "http://127.0.0.1:55005";
};
};
};
2023-08-22 10:50:50 +05:00
# Microboard
"0ch.space" = {
useACMEHost = "0ch.space";
forceSSL = true;
locations = {
"/" = {
proxyPass = "http://127.0.0.1:55006";
};
};
};
2023-08-19 20:27:34 +05:00
2023-08-19 19:41:37 +05:00
# Mail: MTA-STS
"mta-sts.comfycamp.space" = {
useACMEHost = "comfycamp.space";
forceSSL = true;
root = "/var/lib/mta-sts";
};
2023-08-19 12:06:57 +05:00
"matrix.comfycamp.space" = {
useACMEHost = "comfycamp.space";
forceSSL = true;
locations = {
"/".extraConfig = ''
return 404;
'';
# Forward all Matrix API calls to the synapse Matrix homeserver. A trailing slash
# *must not* be used here.
"/_matrix".proxyPass = "http://127.0.0.1:8008";
# Forward requests for e.g. SSO and password-resets.
"/_synapse/client".proxyPass = "http://127.0.0.1:8008";
};
};
2023-08-19 19:41:37 +05:00
# Photoprism
2023-08-19 09:17:27 +05:00
"pp.comfycamp.space" = {
useACMEHost = "comfycamp.space";
forceSSL = true;
locations = {
"/" = {
proxyPass = "http://127.0.0.1:55004";
2023-08-19 09:19:53 +05:00
proxyWebsockets = true;
2023-08-19 09:17:27 +05:00
};
};
};
2023-08-19 19:41:37 +05:00
# Mastodon
2023-08-18 11:21:14 +05:00
"m.comfycamp.space" = {
useACMEHost = "comfycamp.space";
forceSSL = true;
root = "${config.services.mastodon.package}/public/";
locations = {
"/system/" = {
alias = "/var/lib/mastodon/public-system/";
};
"/" = {
tryFiles = "$uri @proxy";
};
"@proxy" = {
proxyPass = "http://unix:/run/mastodon-web/web.socket";
proxyWebsockets = true;
};
"/api/v1/streaming/" = {
proxyPass = "http://unix:/run/mastodon-streaming/streaming.socket";
proxyWebsockets = true;
};
};
};
2023-08-17 21:46:39 +05:00
};
};
2023-08-18 11:21:14 +05:00
users.users.nginx.extraGroups = [ "acme" ];
2023-08-17 21:46:39 +05:00
}