setup anubis in front of forgejo
Some checks are pending
Test Nix flake / Test nix flake (push) Waiting to run

This commit is contained in:
XenGi 2026-12-02 13:29:13 +01:00
commit b4bd52b91e
Signed by: xengi
SSH key fingerprint: SHA256:jxWM2RTHvxxcncXycwwWkP7HCWb4VREN05UGJTbIPZg
3 changed files with 80 additions and 34 deletions

View file

@ -272,7 +272,7 @@
modules = [
agenix.nixosModules.default
{
age.secrets = {};
age.secrets = { };
}
./hosts/prusa-connect
];

View file

@ -10,6 +10,7 @@ let
in
{
imports = [
../../services/anubis.nix
../../services/nginx.nix
../../services/prometheus-nginx.nix
];
@ -74,24 +75,24 @@ in
};
};
anubis.instances.${fqdn}.settings.TARGET = "unix:///run/nginx/${fqdn}.sock";
nginx = {
appendHttpConfig = ''
limit_req_zone $binary_remote_addr zone=forgejo_archive:10m rate=10r/m;
limit_conn_zone $binary_remote_addr zone=forgejo_archive_conn:10m;
'';
virtualHosts."${fqdn}" = {
quic = true;
kTLS = true;
forceSSL = true;
enableACME = true;
extraConfig = ''
merge_slashes off; # Required to handle URL-encoded slashes
proxy_set_header Forwarded "$proxy_forwarded_for_element;$proxy_forwarded_by_element;host=$host;proto=$scheme";
error_log syslog:server=unix:/dev/log,tag=${builtins.replaceStrings [ "." ] [ "_" ] fqdn} warn;
access_log syslog:server=unix:/dev/log vhost_combined;
'';
locations = {
"/" = {
virtualHosts = {
"forgejo.local" = {
listen = [ { addr = "unix:/run/nginx/${fqdn}.sock"; } ];
serverName = fqdn;
extraConfig = ''
merge_slashes off; # Required to handle URL-encoded slashes
proxy_set_header Forwarded "$proxy_forwarded_for_element;$proxy_forwarded_by_element;host=$host;proto=$scheme";
error_log syslog:server=unix:/dev/log,tag=${builtins.replaceStrings [ "." ] [ "_" ] fqdn} warn;
access_log syslog:server=unix:/dev/log vhost_combined;
'';
locations."/" = {
recommendedProxySettings = true;
proxyWebsockets = true;
proxyPass = "http://unix:${config.services.forgejo.settings.server.HTTP_ADDR}";
@ -99,28 +100,42 @@ in
client_max_body_size 512M;
'';
};
"/metrics" = {
recommendedProxySettings = true;
proxyPass = "http://unix:${config.services.forgejo.settings.server.HTTP_ADDR}";
extraConfig = ''
allow 195.160.173.14;
allow 2001:678:760:cccb::14;
deny all;
'';
};
"~ ^/[^/]+/[^/]+/archive/" = {
recommendedProxySettings = true;
proxyPass = "http://unix:${config.services.forgejo.settings.server.HTTP_ADDR}";
extraConfig = ''
limit_req zone=forgejo_archive burst=10 nodelay;
limit_conn forgejo_archive_conn 2;
limit_req_status 429;
'';
};
"= /robots.txt".extraConfig = ''
default_type text/plain;
return 200 "User-agent: *\nDisallow: /*/*/archive/\n";
};
"${fqdn}" = {
quic = true;
kTLS = true;
forceSSL = true;
enableACME = true;
extraConfig = ''
merge_slashes off; # Required to handle URL-encoded slashes
proxy_set_header Forwarded "$proxy_forwarded_for_element;$proxy_forwarded_by_element;host=$host;proto=$scheme";
error_log syslog:server=unix:/dev/log,tag=${builtins.replaceStrings [ "." ] [ "_" ] fqdn} warn;
access_log syslog:server=unix:/dev/log vhost_combined;
'';
locations = {
"/" = {
recommendedProxySettings = true;
proxyWebsockets = true;
#proxyPass = "http://unix:${config.services.forgejo.settings.server.HTTP_ADDR}";
proxyPass = "http://unix:${config.services.anubis.instances.${fqdn}.settings.BIND}";
extraConfig = ''
client_max_body_size 512M;
'';
};
"/metrics" = {
recommendedProxySettings = true;
proxyPass = "http://unix:${config.services.forgejo.settings.server.HTTP_ADDR}";
extraConfig = ''
allow 195.160.173.14;
allow 2001:678:760:cccb::14;
deny all;
'';
};
"= /robots.txt".extraConfig = ''
default_type text/plain;
return 200 "User-agent: *\nDisallow: /*/*/archive/\n";
'';
};
};
};
};

31
services/anubis.nix Normal file
View file

@ -0,0 +1,31 @@
{ config, ... }:
{
users.users.nginx.extraGroups = [
config.services.anubis.defaultOptions.group
];
services.anubis.defaultOptions = {
group = config.services.nginx.group;
policy.extraBots = [
{
name = "XenGis uptime-kuma";
user_agent_regex = "Uptime-Kuma/.*";
remote_addresses = [
"159.195.204.204/32"
"2a0a:4cc0:c2:b028::/64"
];
action = "ALLOW";
}
];
settings = {
BIND_NETWORK = "unix";
DIFFICULTY = 4;
SERVE_ROBOTS_TXT = true;
WEBMASTER_EMAIL = "admin@berlin.ccc.de";
OG_PASSTHROUGH = true;
OG_EXPIRY_TIME = "24h";
REDIRECT_DOMAINS = "*.berlin.ccc.de,berlin.ccc.de";
};
};
}