Apply req limits to fail2ban
This commit is contained in:
parent
c03a508586
commit
61741b5680
1 changed files with 20 additions and 0 deletions
|
@ -74,6 +74,11 @@ let
|
||||||
description = "Extra configuration to inject into the generated nginx config";
|
description = "Extra configuration to inject into the generated nginx config";
|
||||||
default = '''';
|
default = '''';
|
||||||
};
|
};
|
||||||
|
rateLimit.enable = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Enable rate limiting";
|
||||||
|
};
|
||||||
locations = lib.mkOption {
|
locations = lib.mkOption {
|
||||||
type = lib.types.attrsOf (
|
type = lib.types.attrsOf (
|
||||||
lib.khscodes.mkSubmodule {
|
lib.khscodes.mkSubmodule {
|
||||||
|
@ -149,6 +154,16 @@ in
|
||||||
maxretry = 2;
|
maxretry = 2;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
nginx-req-limit = {
|
||||||
|
settings = {
|
||||||
|
filter = "nginx-limit-req";
|
||||||
|
action = ''${config.services.fail2ban.banaction}[name=HTTP, port="http,https"]'';
|
||||||
|
logpath = "/var/log/nginx/access.log";
|
||||||
|
backend = "auto";
|
||||||
|
findtime = 600;
|
||||||
|
maxretry = 3;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
khscodes.networking.aliases = lib.attrsets.attrNames cfg.virtualHosts;
|
khscodes.networking.aliases = lib.attrsets.attrNames cfg.virtualHosts;
|
||||||
khscodes.security.acme.enable = true;
|
khscodes.security.acme.enable = true;
|
||||||
|
@ -177,6 +192,7 @@ in
|
||||||
recommendedZstdSettings = lib.mkDefault true;
|
recommendedZstdSettings = lib.mkDefault true;
|
||||||
recommendedProxySettings = lib.mkDefault true;
|
recommendedProxySettings = lib.mkDefault true;
|
||||||
appendHttpConfig = ''
|
appendHttpConfig = ''
|
||||||
|
limit_req_zone $binary_remote_addr zone=nobots:10m rate=50r/s;
|
||||||
map $scheme $hsts_header {
|
map $scheme $hsts_header {
|
||||||
https "max-age=63072000; preload";
|
https "max-age=63072000; preload";
|
||||||
}
|
}
|
||||||
|
@ -254,8 +270,12 @@ in
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
'''';
|
'''';
|
||||||
|
reqLimit = lib.strings.optionalString value.rateLimit.enable ''
|
||||||
|
limit_req zone=nobots burst=5 nodelay;
|
||||||
|
'';
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
${mtls}
|
${mtls}
|
||||||
|
${reqLimit}
|
||||||
${value.extraConfig}
|
${value.extraConfig}
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue