CrowdSec本地检测、日志解析、IP 自动封禁、iptables/nginx/caddy 拦截插件全部无限制免费,单台服务器终身免费使用,无功能阉割。因为WordPress网站日志分析中发现大量的扫描攻击记录,浪费资源,还影响网站稳定。
下面是一套 Ubuntu + Nginx 下开箱即用、无需额外折腾 的 CrowdSec 标准配置,装完就能自动拦截:漏洞扫描、恶意爬虫、UA 扫描、WP 暴力破解、CONNECT 代理,不用手动加 IP。
全程复制粘贴即可,不搞复杂 yaml 编写。
更多详细可参考github说明:https://github.com/crowdsecurity/crowdsec
1. 一键安装最新版 CrowdSec

官方提供核心是免费的,也有收费功能,一般人没必要,直接使用免费的核心功能即可。
curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | sudo bash
sudo apt update
sudo apt install crowdsec crowdsec-firewall-bouncer-iptables -y
#Ubuntu26.04版本中可能无法识别到,我想也没有人这么快在服务器上使用
2. 安装你需要的防护规则(关键)
直接执行这 4 条,覆盖你所有需求:
# 基础 Nginx 访问日志解析
sudo cscli collections install crowdsecurity/nginx
# 拦截漏洞扫描、路径爆破、PHP 漏洞探测
sudo cscli collections install crowdsecurity/http-cve
# 拦截恶意 UA、爬虫、扫描器
sudo cscli collections install crowdsecurity/http-bad-user-agent
# 拦截 WordPress 暴力破解(wp-login、xmlrpc)
sudo cscli collections install crowdsecurity/wordpress
然后重启生效:
sudo systemctl restart crowdsec
到这里就已经自动工作了,不需要再写任何规则。
3. 它现在会自动拦截什么?
虽然是自动完成,但是我们也至少知道它有什么用。
它会自动拦截:
- 漏洞扫描
eval-stdin.phpvendor/phpunitphpmyadminwp-config.php- 各种路径遍历、SQL 注入、XSS 探测
- 恶意爬虫 / UA
libredtail-httppython-requestscurl/wgetmasscan- 各种 AI 爬虫、采集器
- 暴力破解
- wp-login.php 频繁尝试
- xmlrpc.php 爆破
- 后台路径爆破
- 代理扫描
- CONNECT 请求自动拦截
- 全网共享恶意 IP 别人被扫过的 IP,会提前在你这拉黑。(这个功能很牛,在系统库里的IP再也不能扫了)
4. 查看是否正常运行

# 看状态
sudo systemctl status crowdsec
# 看已安装规则
sudo cscli collections list
# 看当前被拉黑 IP
sudo cscli decisions list
# 看监控指标
sudo cscli metrics
5. 常用命令(你一定会用到)
- 手动拉黑一个 IP
sudo cscli decisions add --ip 170.106.74.215 --duration 24h
- 手动解封
sudo cscli decisions delete --ip 170.106.74.215
更新规则库(每月一次即可)
sudo cscli hub update
sudo cscli hub upgrade
查看攻击日志
sudo tail -f /var/log/crowdsec.log
6. 安全优化(可选,推荐)
白名单自己的 IP,防止误封
把 1.2.3.4 换成你本地公网 IP:(最近也在测试使用,具体效果还在等待一段时间)
sudo cscli parsers add crowdsecurity/whitelists --overwrite
sudo cscli whitelists add ip 1.2.3.4
sudo systemctl reload crowdsec
不想上传攻击数据(完全离线)
默认会匿名上传攻击事件:仅上传攻击者 IP、攻击行为类型、时间戳;不会上传访客浏览记录、网站业务数据、服务器日志原文、用户隐私,符合 GDPR 规范
sudo vim /etc/crowdsec/config.yaml
注释 online_client 整块,彻底离线(官方标准方案)
# 把 online_client 整段全部注释,前面加 #:
yaml
api:
client:
insecure_skip_verify: false
credentials_path: /etc/crowdsec/local_api_credentials.yaml
server:
log_level: info
listen_uri: 127.0.0.1:8080
profiles_path: /etc/crowdsec/profiles.yaml
console_path: /etc/crowdsec/console.yaml
#online_client: # Central API credentials (to push signals and receive bad IPs)
# credentials_path: /etc/crowdsec/online_api_credentials.yaml
重启:
sudo systemctl restart crowdsec
自动拦截漏洞扫描 + 恶意爬虫 + WP 爆破 + 代理扫描 + 全网恶意 IP 自动拉黑不用再手动加 IP,日志会干净 90% 以上。它工作在系统防火墙层面,不修改 Nginx,不影响网站、HTTPS、SEO、百度爬虫。