VPS侦探论坛

标题: nginx 能否禁IP [打印本页]

作者: kkfgef    时间: 2018-8-6 13:54
标题: nginx 能否禁IP
查看了一下nginx的日志,发现有一些IP在一秒内有上百个访问日志
  1. 22.39.58.17 - - [01/Aug/2018:22:34:41 +0800] "HEAD /1cnn%7Bext%7D HTTP/1.1" 444 0 "http://www.xxx.com/1cnn{ext}" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 10.12.17.17 0.000 - - -
  2. 22.39.58.17 - - [01/Aug/2018:22:34:41 +0800] "HEAD /2cnn%7Bext%7D HTTP/1.1" 444 0 "http://www.xxx.com/2cnn{ext}" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 10.12.17.27 0.000 - - -
  3. 22.39.58.17 - - [01/Aug/2018:22:34:41 +0800] "HEAD /3cnn%7Bext%7D HTTP/1.1" 444 0 "http://www.xxx.com/3cnn{ext}" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 10.12.17.37 0.000 - - -
  4. 22.39.58.17 - - [01/Aug/2018:22:34:41 +0800] "HEAD /4cnn%7Bext%7D HTTP/1.1" 444 0 "http://www.xxx.com/4cnn{ext}" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 10.12.17.47 0.000 - - -
  5. 22.39.58.17 - - [01/Aug/2018:22:34:41 +0800] "HEAD /5cnn%7Bext%7D HTTP/1.1" 444 0 "http://www.xxx.com/5cnn{ext}" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 10.12.17.57 0.000 - - -
  6. 22.39.58.17 - - [01/Aug/2018:22:34:41 +0800] "HEAD /6cnn%7Bext%7D HTTP/1.1" 444 0 "http://www.xxx.com/6cnn{ext}" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 10.12.17.67 0.000 - - -
  7. 22.39.58.17 - - [01/Aug/2018:22:34:41 +0800] "HEAD /7cnn%7Bext%7D HTTP/1.1" 444 0 "http://www.xxx.com/7cnn{ext}" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 10.12.17.77 0.000 - - -
  8. 22.39.58.17 - - [01/Aug/2018:22:34:41 +0800] "HEAD /8cnn%7Bext%7D HTTP/1.1" 444 0 "http://www.xxx.com/8cnn{ext}" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 10.12.17.87 0.000 - - -
复制代码


,显然这是不正常的,用nginx能否自动禁止掉这些(按条件,一秒内达多少次访问的同一地址请求)IP呢?用nginx屏蔽IP的话还得重启?nginx应该不能直接使用到iptables吧
作者: licess    时间: 2018-8-6 20:12
上面日志上都已经显示444了,不需要处理
要屏蔽掉head 之类的http方法可以论坛搜索: 屏蔽 http 方法
作者: kkfgef    时间: 2018-8-9 15:26
原帖由 licess 于 2018-8-6 20:12 发表
上面日志上都已经显示444了,不需要处理
要屏蔽掉head 之类的http方法可以论坛搜索: 屏蔽 http 方法
已在NGINX文件中添加了 if ($request_method !~* GET|POST|HEAD) {return 403;}
但在日志中依然发现了这样的访问:
180.97.106.39 - - [09/Aug/2018:03:03:51 +0800] "\x05\x02\x00\x02" 400 166 "-" "-" - 4.170 - - -

120.132.3.65 - - [09/Aug/2018:09:26:34 +0800] "\x00\x9C\x00\x01\x1A+<M\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x03\xFF\xFF\x00\x01local\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00cananian\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 400 166 "-" "-" - 0.014 - - -

......
像这些的都是什么访问格式?如何禁止?
这样添加的内容不对?
server{
        listen 80;
        server_name abc.def.com;           //在下面添加不对?nginx -t显示正确
        if ($request_method !~* GET|POST|HEAD) {
                return 403;
        }
        index index.html index.php;
        root /home/abc;
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        include enable-php.conf;
        location /favicon.ico{
                log_not_found off;
                access_log off;
        }

作者: licess    时间: 2018-8-10 18:14
标题: 回复 3# 的帖子
这个没办法,没有具体的http方法可能是扫描漏洞之类的
作者: woalbb    时间: 2019-1-28 17:00
标题: 回复 1# 的帖子
试试fail2ban
作者: 01rfb    时间: 2019-5-26 15:34
看看,了解一下
作者: Jeremy    时间: 2019-6-1 12:43
我用 fail2ban+Firewalld 限制IP 访问量


补充内容 (2019-6-1 12:58):
https://www.itbiji.net/archives/850.html
可以了解下




欢迎光临 VPS侦探论坛 (https://bbs.lnmp.com/) Powered by Discuz! X3.4