Count IP address in Nginx access logs

摘要: Recently, many referer spam hit on my server, below is the command I used to find and count the IP Address from a Nginx access log file.

Recently, many referer spam hit on my server, below is the command I used to find and count the IP Address from a Nginx access log file.

$ sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr

Full example.

$ sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr
    210 190.104.220.x
    208 181.119.20.x
    134 66.249.69.x
    129 66.249.69.x
    113 37.58.100.x
    108 66.249.69.x
    108 128.204.204.x
    106 37.58.100.x
     99 110.85.69.x
     89 125.78.199.x
     71 128.204.194.x
     70 210.195.94.x
     60 23.19.34.x
Note
The same trick can apply on Apache server access.log.

Next, use below command to find out the access events for a certain IP, then decide what action should be taken next.

$ sudo cat /var/log/nginx/access.log | grep 190.104.220.x

上一篇: Nginx : Block User Agent
下一篇: jsoup : Send search query to Google
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号