fix for duplicate banned IPs in nginx config
This commit is contained in:
parent
4f3c885605
commit
94f57a5f00
1 changed files with 6 additions and 3 deletions
|
@ -21,16 +21,19 @@ map $http_cf_connecting_ip $is_banned {
|
||||||
CONFFILE
|
CONFFILE
|
||||||
|
|
||||||
# Create fail2ban action
|
# Create fail2ban action
|
||||||
echo "Creating fail2ban action..."
|
|
||||||
tee /etc/fail2ban/action.d/nginx-banned-ips.conf << 'ACTIONFILE'
|
tee /etc/fail2ban/action.d/nginx-banned-ips.conf << 'ACTIONFILE'
|
||||||
[Definition]
|
[Definition]
|
||||||
actionstart =
|
actionstart =
|
||||||
actionstop =
|
actionstop =
|
||||||
actioncheck =
|
actioncheck =
|
||||||
actionban = echo '<ip> 1;' >> /etc/nginx/conf.d/banned_ips.conf && nginx -s reload
|
actionban = grep -q '^<ip> 1;$' /etc/nginx/conf.d/banned_ips.conf || echo '<ip> 1;' >> /etc/nginx/conf.d/banned_ips.conf && nginx -s reload
|
||||||
actionunban = sed -i '/<ip>/d' /etc/nginx/conf.d/banned_ips.conf && nginx -s reload
|
actionunban = sed -i '/^<ip> 1;$/d' /etc/nginx/conf.d/banned_ips.conf && nginx -s reload
|
||||||
ACTIONFILE
|
ACTIONFILE
|
||||||
|
|
||||||
|
# Clean up existing duplicates
|
||||||
|
sort -u /etc/nginx/conf.d/banned_ips.conf > /etc/nginx/conf.d/banned_ips.conf.tmp && \
|
||||||
|
mv /etc/nginx/conf.d/banned_ips.conf.tmp /etc/nginx/conf.d/banned_ips.conf
|
||||||
|
|
||||||
# Test NGINX configuration
|
# Test NGINX configuration
|
||||||
echo "Testing NGINX configuration..."
|
echo "Testing NGINX configuration..."
|
||||||
nginx -t
|
nginx -t
|
||||||
|
|
Loading…
Reference in a new issue