-
-
Save fengqi/18050b2926fe05cdd5597a4ad6ac8b74 to your computer and use it in GitHub Desktop.
nginx自动屏蔽扫描的ip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| line=1000 | |
| times=10 | |
| conf=/opt/nginx/conf/blockip.conf | |
| tail /data/logs/nginx/access.log -n $line | \ | |
| grep -E '("status":"404"|"status":"302")' | jq -r '.remote_addr' | \ | |
| sort | uniq -c | \ | |
| awk '$1>$times{print "deny "$2 ";"}' >> $conf | |
| deny=$(sort $conf | uniq -c | awk '{print "deny "$3}') | |
| echo $deny | sed "s/; /;\n/g" > $conf | |
| /usr/local/sbin/nginx -t || exit | |
| /usr/bin/systemctl reload nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment