Last active
August 29, 2015 14:25
-
-
Save hjue/1d63196207c7d6d34f6b to your computer and use it in GitHub Desktop.
nginx block ipaddress
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 | |
| nginx_home=/opt/nginx | |
| log_path=$nginx_home/logs | |
| tail -n50000 $log_path/access.log \ | |
| |awk '{print $1,$12}' \ | |
| |grep -i -v -E "google|yahoo|baidu|msnbot|FeedSky|sogou|127.0.0.1" \ | |
| |awk '{print $1}'|sort|uniq -c|sort -rn \ | |
| |awk '{if($1>1000)print "deny "$2";"}' >$nginx_home/conf/vhosts/blockip.conf | |
| $nginx_home/sbin/nginx -s reload | |
| #include vhosts/blockip.conf; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment