惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 最新话题
小众软件
小众软件
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
T
Tailwind CSS Blog
Recorded Future
Recorded Future
雷峰网
雷峰网
WordPress大学
WordPress大学
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
T
Tor Project blog
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Spread Privacy
Spread Privacy
G
Google Developers Blog
Security Latest
Security Latest
MongoDB | Blog
MongoDB | Blog
T
Threatpost
I
InfoQ
T
Tenable Blog
T
The Exploit Database - CXSecurity.com
S
Security Affairs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
C
Cisco Blogs
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
aimingoo的专栏
aimingoo的专栏
C
CXSECURITY Database RSS Feed - CXSecurity.com
美团技术团队
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
D
Docker
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
PCI Perspectives
PCI Perspectives
Microsoft Azure Blog
Microsoft Azure Blog
C
CERT Recently Published Vulnerability Notes
月光博客
月光博客
Cloudbric
Cloudbric
A
About on SuperTechFans
F
Fortinet All Blogs

Liups233の小站

YubiKey OpenPGP 智能卡使用指南 - Liups233の小站 通过 WKD / OPENPGPKEY DNS 记录部署 GPG 公钥 - Liups233の小站 OpenLiteSpeed 安装与建站配置 详细教程 - Liups233 使用 DNSCrypt-Proxy 为 Linux 配置加密 DNS - Liups233 WordPress 7.0 编辑器改回无衬线字体 - Liups233の小站 Redis 数据库权限与 Unix Socket 配置 - Liups233の小站 Cloudflare 设置 mTLS 验证来源拉取 - Liups233の小站 Docker 自建 RustDesk 远程和 API 服务 - Liups233の小站 ChatGPT Go 印度区免费试用白嫖 1 年 - Liups233の小站 使用 S/MIME 证书签名并加密电子邮件 - Liups233の小站 为 WordPress 外发邮件添加 S/MIME 签名 - Liups233の小站 网站域名变更迁移教程/记录 - Liups233の小站 将动漫视频刻录为视频光盘-蓝光/AVCHD DVD - Liups233の小站 百乐 CUSTOM 912 钢笔使用体验 - Liups233の小站 使用 Cloudflare mTLS 用户端凭证保护博客登入页面 - Liups233の小站 Kobo 手动安装 NickelMenu 和 KOReader - Liups233の小站 Kobo 阅读器字典缺字解决 - Liups233の小站 iCloud+ 域名邮箱的注册和使用 - Liups233の小站 9 美元一年的通配符 SSL 证书 - Liups233の小站 宝塔面板 Nginx 启用 Brotli 和 Pagespeed - Liups233の小站 拷贝 DVD/Blu-ray 光盘并使用 MeGUI 压制 - Liups233の小站 Spotify 相较 Apple Music 的优点 - Liups233の小站 欧卡/美卡自定义手排挡位布局 - Liups233の小站 内地居民到港开户汇丰和中银香港全过程 - Liups233の小站 给光驱刷入 LibreDrive 固件解锁区域和加密限制 - Liups233の小站 为Kobo阅读器添加Google Drive和Dropbox功能 - Liups233の小站 百乐 PILOT Capless Fermo 钢笔评测 - Liups233の小站 业余无线电 B 类考试笔记 - Liups233の小站 黑白阅读器的绝唱?Kobo Clara BW 简单评测 - Liups233の小站 八重洲 WIRES-X 网络注册与使用教程 - Liups233の小站 异世的同路人 — 恋语 Juliamo 游戏简评 - Liups233の小站 欢迎加入我的 FreeDMR 服务器 - Liups233の小站 低至 6 港币一年的 Club SIM eSIM 保号卡 - Liups233の小站 H310/H710(P)/H810 阵列卡刷写为直通模式 - Liups233の小站
个人博客适用的 Cloudflare 防火墙和缓存规则 - Liups233の小站
Liups233 · 2024-10-07 · via Liups233の小站
个人博客适用的 Cloudflare 防火墙和缓存规则

前言

作为全球最知名和良心的免费 CDN 服务商,Cloudflare 被许多建站小白和穷人(比如我)应用在网站上。虽然免费的 CDN 服务经常被国内的朋友叫作「网站减速器」,不过我感觉其实也没有慢得那么离谱,下面是我在晚上 8 点测试的网站主页速度,基本都能在两秒内打开(服务器在美国德州)。

晚上 8 点在 ITDOG 测试的 Cloudflare 网站速度
晚上 8 点在 ITDOG 测试的网站速度

虽然 Cloudflare 有时会降低网站速度,不过它能给网站套一层安全盾,缓解逆天的 DDoS 攻击和恶意机器人,所以还是很有用的。这篇文章就分享我的 Cloudflare WAF 和其它的安全配置,可以给同样做个人网站的朋友参考下,也欢迎提出一些改正方案。

目录

第一规则:允许已知的机器人和 User-Agent

表达式:

(cf.client.bot) or (http.user_agent contains "SafariViewService") or (http.user_agent contains "WeChatShareExtensionNew")

操作:跳过

放置位置:第一个

第二规则:固定 Captcha 验证

表达式:

(ip.geoip.country in {"RU" "T1" "IE"} and not cf.client.bot) or (not http.request.version in {"HTTP/2" "HTTP/3" "SPDY/3.1"}) or (http.user_agent eq "") or (http.user_agent contains "fuck") or (http.user_agent contains "lient" and http.user_agent contains "ttp") or (http.user_agent contains "java") or (http.user_agent contains "Joomla") or (http.user_agent contains "libweb") or (http.user_agent contains "libwww") or (http.user_agent contains "PHPCrawl") or (http.user_agent contains "PyCurl") or (http.user_agent contains "python") or (http.user_agent contains "wrk") or (http.user_agent contains "hey") or (http.user_agent contains "Acunetix") or (http.user_agent contains "apache") or (http.user_agent contains "BackDoorBot") or (http.user_agent contains "cobion") or (http.user_agent contains "masscan") or (http.user_agent contains "FHscan") or (http.user_agent contains "scanbot") or (http.user_agent contains "Gscan") or (http.user_agent contains "Researchscan") or (http.user_agent contains "WPScan") or (http.user_agent contains "ScanAlert") or (http.user_agent contains "Wprecon") or (http.user_agent contains "virusdie") or (http.user_agent contains "VoidEYE") or (http.user_agent contains "WebShag") or (http.user_agent contains "Zeus") or (http.user_agent contains "zgrab") or (http.user_agent contains "zmap") or (http.user_agent contains "nmap") or (http.user_agent contains "fimap") or (http.user_agent contains "ZmEu") or (http.user_agent contains "ZumBot") or (http.user_agent contains "Zyborg") or (http.user_agent contains "attachment") or (http.user_agent contains "undefined")

操作:交互式质询(互动式查问)

放置位置:最后一个

其他适用于 WordPress 的设置

在搜索、进入后台、发布评论时进行 Captcha 验证

在「规则」「Configuration Rules」中添加一条规则。

表达式:

(http.request.uri contains "/?s=") or (http.request.uri.path contains "wp-login.php") or (http.request.uri.path contains "wp-comments-post.php")

浏览器完整性检查:启用

安全级别:I’m Under Attack

放置位置:第一个

禁止缓存后台和搜索页

在「规则」「Cache Rules」中添加一条规则。

如果:自定义筛选表达式

表达式:

(http.host eq "填写你的域名" and not starts_with(http.request.uri.path, "/wp-admin") and not starts_with(http.request.uri.path, "/wp-login") and not starts_with(http.request.uri.path, "/wp-json/") and not starts_with(http.request.uri.path, "/wc-api/") and not starts_with(http.request.uri.path, "/edd-api/") and not starts_with(http.request.uri.path, "/mepr/") and not http.request.uri.path contains "/register/" and not http.request.uri.path contains "/dashboard/" and not http.request.uri.path contains "/members-area/" and not http.request.uri.path contains "/wishlist-member/" and not http.request.uri.path contains "phs_downloads-mbr" and not http.request.uri.path contains "/checkout/" and not http.request.uri.path contains ".xsl" and not http.request.uri.path contains ".xml" and not http.request.uri.path contains ".php" and not starts_with(http.request.uri.query, "s=") and not starts_with(http.request.uri.query, "p=") and not http.request.uri.query contains "nocache" and not http.request.uri.query contains "nowprocket" and not http.cookie contains "wordpress_logged_in_" and http.cookie ne "comment_" and not http.cookie contains "woocommerce_" and not http.cookie contains "wordpressuser_" and not http.cookie contains "wordpresspass_" and not http.cookie contains "wordpress_sec_" and not http.cookie contains "yith_wcwl_products" and not http.cookie contains "edd_items_in_cart" and not http.cookie contains "it_exchange_session_" and not http.cookie contains "comment_author" and not http.cookie contains "dshack_level" and not http.cookie contains "auth_" and not http.cookie contains "noaffiliate_" and not http.cookie contains "mp_session" and not http.cookie contains "xf_" and not http.cookie contains "mp_globalcart_" and not http.cookie contains "wp-resetpass-" and not http.cookie contains "upsell_customer" and not http.cookie contains "wlmapi" and not http.cookie contains "wishlist_reg")

缓存资格:符合缓存条件

边缘 TTL:忽略缓存控制标头,使用此 TTL:1 天

浏览器 TTL:替代源服务器,使用此 TTL:4 小时

放置位置:第一个

总结

思路来源:
【調教Wordpress】套Cloudflare後如何避免快取admin bar – WordPress – 公牛擠奶 (rapbull.net)
WordPress插件Super Page Cache for Cloudflare的SF规则设置部分 – 技术宅银魂 – 科技改变生活 – 万事屋 (rei3.com)
如何保护您的 WordPress 具有 Cloudflare 防火墙规则的站点 (websiterating.com, saved by Wayback Machine)

这篇文章只是抛砖引玉,您可以修改以适用其他平台。我个人其实也对 Cloudflare 的功能没有深究过,有任何建议也欢迎留言。

欢迎看看我主页的其他内容

最后修改日期: 2026-05-22

作者