infra/config/services/nginx.nix

56 lines
1.5 KiB
Nix
Raw Normal View History

2024-09-18 16:10:20 +02:00
{ config, pkgs, ... }:
let
snakeoilCert = pkgs.runCommand "nginx-snakeoil-cert" { buildInputs = [ pkgs.openssl ]; } ''
mkdir "$out"
openssl req -newkey rsa:4096 -x509 -sha256 -days 36500 -subj '/CN=Snakeoil CA' -nodes -out "$out/cert.pem" -keyout "$out/cert.key"
'';
2024-09-18 16:10:20 +02:00
in
{
2023-05-06 06:49:46 +02:00
services.nginx = {
enable = true;
package = pkgs.nginxMainline;
2024-09-13 18:46:44 +02:00
recommendedBrotliSettings = true;
2023-05-06 06:49:46 +02:00
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
2024-09-13 18:46:44 +02:00
recommendedZstdSettings = true;
2023-05-06 06:49:46 +02:00
# https://github.com/NixOS/nixpkgs/issues/180980#issuecomment-1179723811
virtualHosts = {
"defaultDummy404" = {
default = true;
serverName = "_";
locations."/".extraConfig = "return 444;";
2023-05-06 06:49:46 +02:00
locations."/.well-known/acme-challenge".root = "/var/lib/acme/acme-challenge";
};
"defaultDummy404ssl" = {
2023-05-06 06:49:46 +02:00
default = true;
serverName = "_";
locations."/".extraConfig = "return 444;";
2023-05-06 06:49:46 +02:00
locations."/.well-known/acme-challenge".root = "/var/lib/acme/acme-challenge";
# Dummy SSL config
onlySSL = true;
sslCertificate = "${snakeoilCert}/cert.pem";
sslCertificateKey = "${snakeoilCert}/cert.key";
};
};
2024-09-13 18:46:44 +02:00
sslDhparam = config.security.dhparams.params.nginx.path;
};
security.dhparams = {
enable = true;
2024-09-18 16:10:20 +02:00
params.nginx = { };
2023-05-06 06:49:46 +02:00
};
2024-09-18 16:10:20 +02:00
networking.firewall.allowedTCPPorts = [
80
443
];
# allow nginx to access Acme secrets
2024-09-18 16:10:20 +02:00
users.users.nginx.extraGroups = [ "acme" ];
2023-05-06 06:49:46 +02:00
}