速率限製配置錯誤的機器人

速率限製配置錯誤的機器人

我們在負載平衡器後面有一個 Nginx / PHP-FPM,它會定期被抓取。許多抓取工具都嚴重攻擊我們應用程式的 404 頁面。

Nginx 有沒有辦法,可能與限速模組或不同的模組,在每分鐘超過 100 個請求出現 404 錯誤後阻止基於 x-forward-for 的所有流量?

我找到的文檔限制請求模組看起來它是基於資源而不是頁面返回狀態。

有足夠的流量,每個節點都會看到足夠的 404 流量,因此它們不需要就集體阻止誰進行通訊。

答案1

您當然可以使用 limit_req_zone 模組在 nginx 中執行此操作。

在 nginx.conf 中設定一個區域:

limit_req_zone $binary_remote_addr zone=one:1000m   rate=100r/m;

你也可以用tooX_Forwarded_For來代替binary_remote_addr

在您的網站配置位置區塊中,只需引用該區域:

limit_req zone=one burst=10 nodelay;

文件: http://nginx.org/en/docs/http/ngx_http_limit_req_module.html

答案2

您可以使用fail2ban並使用以下帶有nginx的監獄來限製配置錯誤的機器人

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

相關內容