我们有一个负载均衡器后面的Nginx / PHP-FPM,它会定期获取。 许多刮板在我们的应用程序的404页面上安静地打了一下。
Nginx有没有一种方法可以在速率限制模块或不同模块的基础上阻止所有基于x-forward-for的stream量,在每分钟超过100个请求时发生404错误?
我发现的limit-req-module文档看起来像是基于资源而不是页面返回状态。
有足够的stream量,每个节点都看到足够的stream量,他们不应该需要沟通谁集体阻止。
你当然可以在nginx中用limit_req_zone模块来做到这一点。
在nginx.conf中设置一个区域:
limit_req_zone $binary_remote_addr zone=one:1000m rate=100r/m;
您也可以使用X_Forwarded_For而不是binary_remote_addr 。
在您的网站configuration位置块只是参考区域:
limit_req zone=one burst=10 nodelay;
doc: http : //nginx.org/en/docs/http/ngx_http_limit_req_module.html
你可以使用fail2ban,并使用下面的nginx监狱来限制错误configuration的机器人
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local并将其添加到底部
[nginx-req-limit] enabled = true filter = nginx-req-limit action = iptables-multiport[name=ReqLimit, port="http,https", protocol=tcp] logpath = /var/log/nginx/*error.log findtime = 600 bantime = 7200 maxretry = 10
引用: https : //rtcamp.com/tutorials/nginx/fail2ban