Cloudflare 免费安全功能配置指南
🆓 免费版可用的安全功能
虽然完整的 WAF 需要付费,但 Cloudflare 免费版仍然提供强大的安全保护!
✅ 1. Security Level(安全级别)
位置: Dashboard > Security > Settings
免费功能:
- ✅ Security Level: Medium/High/I'm Under Attack
- ✅ Challenge Passage: 自动验证可疑访问者
推荐配置:
Security Level: High
Challenge Passage: 30 分钟
Browser Integrity Check: 启用
✅ 2. Firewall Rules(防火墙规则)
位置: Dashboard > Security > WAF > Firewall rules
免费额度: 5 条规则
推荐规则:
规则 1: 阻止常见攻击路径
Expression:
(http.request.uri.path contains "/admin" and cf.threat_score > 10) or
(http.request.uri.path contains "/.env") or
(http.request.uri.path contains "/config") or
(http.request.uri.path contains "phpMyAdmin")
Action: Block
规则 2: 保护 API 端点(速率限制)
Expression:
(http.request.uri.path contains "/api/chat") and
(rate(5m) > 100)
Action: Challenge
规则 3: 阻止高风险国家(可选)
Expression:
ip.geoip.country in {"RU" "CN" "KP"}
and http.request.uri.path contains "/admin"
Action: Challenge
规则 4: 只允许特定 User-Agent
Expression:
not (http.user_agent contains "Mozilla" or
http.user_agent contains "Chrome" or
http.user_agent contains "Safari")
Action: Challenge
规则 5: SQL 注入保护
Expression:
(http.request.uri contains "union select") or
(http.request.uri contains "' or '1'='1") or
(http.request.body contains "drop table")
Action: Block
✅ 3. Rate Limiting(速率限制)
位置: Dashboard > Security > WAF > Rate limiting rules
免费额度:
- ✅ 基础速率限制(10条规则)
- ❌ 高级速率限制(付费)
推荐配置:
API 保护
Name: API Rate Limit
If: (http.request.uri.path contains "/api/")
Then: Rate limit
Requests: 100 per 1 minute
Duration: 10 minutes
Action: Block
登录保护
Name: Login Rate Limit
If: (http.request.uri.path eq "/api/auth/login")
Then: Rate limit
Requests: 5 per 5 minutes
Duration: 30 minutes
Action: Block
✅ 4. Bot Fight Mode(免费 Bot 防护)
位置: Dashboard > Security > Bots
免费功能:
- ✅ Bot Fight Mode(基础 Bot 检测和阻止)
- ❌ Super Bot Fight Mode(付费,更精准)
推荐: 启用 Bot Fight Mode
✅ 5. Page Rules(页面规则)
位置: Dashboard > Rules > Page Rules
免费额度: 3 条规则
推荐配置:
规则 1: 静态资源缓存
URL: mbe-dev.hi-maker.com/static/*
Settings:
- Cache Level: Cache Everything
- Edge Cache TTL: 1 month
- Browser Cache TTL: 1 day
规则 2: API 不缓存
URL: mbe-dev.hi-maker.com/api/*
Settings:
- Cache Level: Bypass
规则 3: 管理后台额外保护
URL: mbe-dev.hi-maker.com/admin/*
Settings:
- Security Level: I'm Under Attack
- Browser Integrity Check: On
✅ 6. SSL/TLS 设置
位置: Dashboard > SSL/TLS
推荐配置:
SSL/TLS encryption mode: Full (strict)
Minimum TLS Version: TLS 1.2
Opportunistic Encryption: 开启
TLS 1.3: 开启
Automatic HTTPS Rewrites: 开启
✅ 7. Transform Rules(免费)
位置: Dashboard > Rules > Transform Rules
用途: 修改请求/响应 Headers
添加安全 Headers
Modify Response Header:
- X-Frame-Options: SAMEORIGIN
- X-Content-Type-Options: nosniff
- X-XSS-Protection: 1; mode=block
- Referrer-Policy: strict-origin-when-cross-origin
✅ 8. DDoS 保护(自动启用)
位置: Dashboard > Security > DDoS
免费功能:
- ✅ 自动 DDoS 防护(L3/L4 网络层)
- ✅ HTTP DDoS 攻击保护(L7 应用层)
- ✅ 无流量限制
无需配置,自动保护!
✅ 9. Managed Challenge(免费)
位置: Dashboard > Security > Settings
功能:
- ✅ 智能验证可疑访问者
- ✅ 无需 CAPTCHA(更好的用户体验)
- ✅ 基于设备指纹和行为分析
🎯 快速配置步骤
Step 1: 基础安全设置
- Security > Settings
- Security Level: High
- Browser Integrity Check: On
Step 2: 创建防火墙规则
- Security > WAF > Firewall rules
- 添加上面推荐的 5 条规则
Step 3: 启用 Bot 防护
- Security > Bots
- 启用 Bot Fight Mode
Step 4: 配置速率限制
- Security > WAF > Rate limiting rules
- 添加 API 和登录保护规则
Step 5: SSL/TLS 优化
- SSL/TLS > Overview
- 设置为 Full (strict)
- 启用 TLS 1.3
📊 安全效果对比
| 功能 | 免费版 | 付费版 |
|---|---|---|
| DDoS 防护 | ✅ 无限 | ✅ 增强 |
| SSL/TLS | ✅ 免费证书 | ✅ 高级证书 |
| Firewall Rules | ✅ 5条 | ✅ 更多 |
| Rate Limiting | ✅ 基础 | ✅ 高级 |
| Bot Fight Mode | ✅ 基础 | ✅ Super |
| WAF Managed Rules | ❌ 付费 | ✅ 完整 |
| Page Rules | ✅ 3条 | ✅ 更多 |
💡 对于 MBE 项目的建议
基于您的使用场景(开发/测试环境),免费版已经足够!
推荐启用(优先级从高到低):
- ✅ Firewall Rules - 阻止常见攻击
- ✅ Rate Limiting - 保护 API 端点
- ✅ Bot Fight Mode - 防止恶意爬虫
- ✅ SSL/TLS Full (strict) - 确保加密
- ✅ Security Level: High - 更严格验证
可选:
- Page Rules(如果有静态资源)
- Transform Rules(添加安全 Headers)
🔗 快速链接
- Firewall Rules: https://dash.cloudflare.com/[your-account]/hi-maker.com/security/waf/firewall-rules
- Rate Limiting: https://dash.cloudflare.com/[your-account]/hi-maker.com/security/waf/rate-limiting-rules
- Bots: https://dash.cloudflare.com/[your-account]/hi-maker.com/security/bots
- Settings: https://dash.cloudflare.com/[your-account]/hi-maker.com/security/settings
免费版 Cloudflare 已经提供了企业级的基础防护! 🛡️
如果以后流量增大或需要更精细的控制,再考虑升级到付费版。