Skip to content

Instantly share code, notes, and snippets.

@hjue
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save hjue/1d63196207c7d6d34f6b to your computer and use it in GitHub Desktop.

Select an option

Save hjue/1d63196207c7d6d34f6b to your computer and use it in GitHub Desktop.
nginx block ipaddress
#!/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