Skip to content

Instantly share code, notes, and snippets.

@oerdnj
Created December 18, 2019 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oerdnj/0d3c3870e1fe3b1d705218e237843b68 to your computer and use it in GitHub Desktop.
Save oerdnj/0d3c3870e1fe3b1d705218e237843b68 to your computer and use it in GitHub Desktop.
#!/bin/sh
# place into /etc/logrotate.d/httpd-prerotate/nginx-deny-list
TMPF=$(mktemp /etc/nginx/deny-ip.conf.XXXXXX) && (
(list-abusers /var/log/nginx/packages.sury.org-access.log) | sort -u > "$TMPF"
if ! diff -q /etc/nginx/deny-ip.conf "$TMPF" >/dev/null; then
mv /etc/nginx/deny-ip.conf /etc/nginx/deny-ip.conf.bak
mv "$TMPF" /etc/nginx/deny-ip.conf
if nginx -q -t; then
nginx -q -s reload
rm /etc/nginx/deny-ip.conf.bak
else
mv /etc/nginx/deny-ip.conf.bak /etc/nginx/deny-ip.conf
fi
else
rm "$TMPF"
fi
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment