nginx - 如何使用 fail2ban 处理 Nginx 错误“主脚本未知”
问题描述
我使用 Ubuntu 20.04 和 Fail2ban,但不会过滤此类错误。此错误出现在 /var/log/nginx/error.log 中。如何在 Fail2ban 中进行设置以阻止这样的机器人?
2020/12/31 18:02:34 [错误] 674#674: *1003 FastCGI 在标准错误中发送:“主要脚本未知”同时从上游读取响应标头,客户端:xxx.xxx.xxx.xxx,服务器:mydomain。 com,请求:“GET /wp-content/plugins/eshop-magic/download.php?file=../../../../wp-config.php HTTP/1.1”,上游:“fastcgi: //unix:/var/run/php/php7.4-fpm.sock:",主机:" www.mydomain.com "
注意:我想阻止所有 IP 地址尝试访问不存在的网页,使用 fail2ban。我无法在 filter.d 上构建正确的正则表达式
解决方案
[nginx-badbots]
在您的jail.local
[nginx-badbots]
enabled = true
port = http,https
filter = nginx-badbots
logpath = /var/log/nginx/error.log
maxretry = 2
创建一个名为nginx-badbots.conf
inside的过滤器文件filter.d
[Definition]
failregex = FastCGI sent in stderr: "Primary script unknown" .*, client: <HOST>
ignoreregex =
重启fail2ban
service fail2ban restart
检查你的nginx-badbots
监狱
fail2ban-client status nginx-badbots
推荐阅读
- php - 如何增加会话数组值?
- c# - 使用 Entity Framework sql 将 Null 插入数据库
- python - Upload multi img to 1 post on Django ? How do that?
- python - 使用 Python z3 API 简化方程
- android - Viewpager inside recyclerView dissapears when scrolling up or down
- c++ - 使用填充构造函数初始化向量的向量
- javascript - 在一个功能中加载图像
- elasticsearch - 聚合是否可以将所有分组文档中的数组属性的所有值合并到合并文档中?
- javascript - JavaScript scroll() event endless loop when page scrolled to the bottom
- python - 将 Spark DataFrame 的架构转换为另一个 DataFrame