added nginx-badbots fail2ban rule https://stackoverflow.com/a/65552146

This commit is contained in:
Bachir Soussi Chiadmi 2023-03-31 11:27:55 +02:00
parent d2380db06b
commit 4b3ccb3fff
3 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,5 @@
[Definition]
failregex = FastCGI sent in stderr: "Primary script unknown" .*, client: <HOST>
ignoreregex =

View File

@ -0,0 +1,7 @@
[nginx-badbots]
enabled = true
port = http,https
filter = <FILTER>
logpath = <LOGPATH>
maxretry = 2

View File

@ -106,6 +106,16 @@ if [ "$vh" = "y" ]; then
chmod -R g+w /var/www/"$_domain"/
chmod -R g+r /var/www/"$_domain"/
#set fail2ban for vhost
# https://stackoverflow.com/a/65552146
cp "$_assets/fail2ban/jail.d/nginx-badbots.conf" "/etc/fail2ban/jail.d/nginx-badbots-$_domain.conf"
sed -i -r "s/\[nginx-badbots\]/\[nginx-badbots-$_domain\]/g" "/etc/fail2ban/jail.d/nginx-badbots-$_domain.conf"
sed -i -r "s/<FILTER>/\[nginx-badbots-$_domain\]/g" "/etc/fail2ban/jail.d/nginx-badbots-$_domain.conf"
sed -i -r "s/<LOGPATH>/\/var\/www\/$_domain\/log\/error.log/g" "/etc/fail2ban/jail.d/nginx-badbots-$_domain.conf"
cp "$_assets/fail2ban/filter.d/nginx-badbots.conf" "/etc/fail2ban/filter.d/nginx-badbots-$_domain.conf"
sed -i -r "s/<HOST>/$_domain/g" "/etc/fail2ban/filter.d/nginx-badbots-$_domain.conf"
# create a shortcut to the site