最近主机被人刷了,我写了个脚本,对nginx访问日志分析,发现访问量大于3000的ip就加入到nginx的黑名单中去,但是这个我发现虽然能防住刷主机的垃圾,但是有可能误杀一些正常的访问ip,于是我想只仅处理最近1小时的访问记录,对其ip进行分析,如果访问量太大就封杀,但是搜了半天无果,请大神帮忙看看,谢谢。
nginx_access 日志格式如下:
66.249.79.234 - - [20/Aug/2022:02:18:51 +0800] "GET /healthy-eating/ HTTP/1.1" 200 8448 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" "-"
nginx_error 日志格式如下:
2022/08/16 17:48:11 [error] 36492#0: *10499 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 54.36.148.246, server: new.taobao.com, request: "GET /link.php?url=http://pinkberrylicious.blogspot.com/2016/07/clone-sony-x-bo-v11-lollipop-51.html HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php-fpm.sock:", host: "www.taobao.com"
nginx_access
时间格式不好判断,我是按照
nginx_error
的时间格式来的,(nginx日志的输出格式可以指定的)
日志格式是:
66.249.79.234 - - [2022/08/16 17:48:11] "GET /healthy-eating/
按照最初时间格式的改进写法:
66.249.79.234 - - [20/Aug/2022:02:18:51 +0800] "GET /healthy-eating
nginx_error
按照楼主提供的日志格式:
2022/08/16 17:48:11 xxxxxx client: 54.36.148.246