2023-04-14 13:20:51 +00:00
|
|
|
{ pkgs, lib, config, ... }:
|
2023-03-06 09:21:34 +00:00
|
|
|
|
2023-03-05 22:51:30 +00:00
|
|
|
{
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
2023-03-06 09:21:34 +00:00
|
|
|
package = pkgs.nginxQuic;
|
|
|
|
|
2023-03-05 22:51:30 +00:00
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedBrotliSettings = true;
|
2023-04-03 12:05:24 +00:00
|
|
|
recommendedZstdSettings = true;
|
2023-03-05 22:51:30 +00:00
|
|
|
recommendedTlsSettings = true;
|
2023-03-13 22:28:01 +00:00
|
|
|
|
|
|
|
commonHttpConfig = ''
|
|
|
|
map $remote_addr $remote_addr_anon {
|
|
|
|
~(?P<ip>\d+\.\d+\.\d+)\. $ip.0;
|
|
|
|
~(?P<ip>[^:]+:[^:]+): $ip::;
|
|
|
|
default 0.0.0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_format combined_anon '$remote_addr_anon - $remote_user [$time_local] '
|
|
|
|
'"$request" $status $body_bytes_sent '
|
|
|
|
'"$http_referer" "$http_user_agent"';
|
|
|
|
|
2023-03-13 22:42:19 +00:00
|
|
|
access_log /var/log/nginx/access.log combined_anon buffer=32k flush=5m;
|
2023-03-13 22:28:01 +00:00
|
|
|
'';
|
2023-03-05 22:51:30 +00:00
|
|
|
};
|
2023-03-06 08:55:28 +00:00
|
|
|
|
2023-04-14 18:19:51 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /run/nginx-sockets 0777 root root"
|
|
|
|
];
|
|
|
|
|
2023-04-14 14:21:39 +00:00
|
|
|
networking.firewall.interfaces =
|
|
|
|
let
|
2023-04-14 15:24:46 +00:00
|
|
|
interfaces = lib.mapAttrsToList (_: value: lib.attrsets.attrByPath [ "matchConfig" "Name" ] null value) config.systemd.network.networks ++ [ "tailscale0" ];
|
2023-04-14 14:21:39 +00:00
|
|
|
in
|
|
|
|
builtins.listToAttrs
|
|
|
|
(builtins.map
|
|
|
|
(iface:
|
|
|
|
{
|
|
|
|
name = iface;
|
|
|
|
value = {
|
|
|
|
allowedTCPPorts = [ 80 443 ];
|
|
|
|
allowedUDPPorts = [ 443 ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(builtins.filter builtins.isString interfaces));
|
2023-03-05 22:51:30 +00:00
|
|
|
}
|