白嫖 Cloudflare 最优 CDN + 双域名彻底隐藏服务器 IP,黑客再也扫不到我了(保姆级实战教程)

Multi-vendor Application Security and Performance Reference Architecture · Cloudflare Reference Architecture docs
黑客正在扫描你的服务器 IP!我是怎么用两个域名 + Workers 白嫖 Cloudflare 最优 CDN,把速度提升 3 倍的(完整保姆级教程)
大家好,我是波波老师。
如果你还能轻松 ping 到自己的服务器 IP,那我必须提醒你:
你的服务器正在裸奔,被黑客持续扫描。
每天都有大量自动化工具在扫描暴露的 IP,一旦被盯上,DDoS、恶意爬虫、数据泄露……风险极高。我以前也因为 IP 暴露吃过亏,后来彻底改用两个域名 + Workers 的玩法,才真正睡得安心。
今天把这套既能隐藏 IP、又能大幅提速的实战方案完整分享出来,小白也能一步步照着做。
核心结论
一个域名对外服务,一个域名专门做中转优选,再配合 Workers 智能路由,就能在 Free 计划下实现高速 + 隐身 + 强防御。
整体架构示意图

Cloudflare + the edge - by Sam Crowder - Cloud Constructed
完整配置步骤
步骤 1:准备两个域名并接入 Cloudflare
主域名(对外访问):example.com
辅助域名(中转优选):cdn.example.net
两个域名全部改 NS 到 Cloudflare 并激活
步骤 2:在辅助域名上创建 CDN 入口
在 cdn.example.net 添加以下记录(全部开启橙色云朵 Proxied):
cdn.cdn.example.net → A → 你的服务器 IP
cdnshop.cdn.example.net → A → 你的服务器 IP
cdndocs.cdn.example.net → A → 你的服务器 IP
步骤 3:在主域名配置 CNAME(最核心一步)

CNAME record do not work - DNS & Network - Cloudflare Community
在 example.com DNS 中设置:
| 类型 | 名称 | 内容 | Proxy |
|---|---|---|---|
| CNAME | @ | cdn.cdn.example.net | 橙色 |
| CNAME | www | cdn.cdn.example.net | 橙色 |
| CNAME | shop | cdnshop.cdn.example.net | 橙色 |
| CNAME | docs | cdndocs.cdn.example.net | 橙色 |
步骤 4:服务器端安全配置(防黑客关键)
nginx
server { listen 80; listen 443 ssl; server_name example.com www.example.com shop.example.com docs.example.com cdn.cdn.example.net cdnshop.cdn.example.net cdndocs.cdn.example.net; root /var/www/html;}
前面步骤的进阶玩法:让 Claude Code 通过 MCP 自动帮我配置
当你已经装好 MCP + ssh-manager 后,可以直接让 Claude Code 自己去 Cloudflare 配置域名,省时省力。
直接复制下面 Prompt 发给 Claude Code:
text
You are now connected to my server via mcp-ssh-manager.I want you to configure optimal double-domain Cloudflare CDN to completely hide my origin server IP (138.68.253.102).Domains needed:- shop.gaoai.co (main, port 80)- cdnshopadmin.gaoai.co (admin + backup, port 81)- www.gaoai.co → point to 138.68.253.102:4000/console- doc.gaoai.co (static docs)Please use my Cloudflare Zone API Token to:1\. Check current DNS records2\. Set proper A/CNAME records with Proxy enabled (orange cloud)3\. Set SSL to Full (strict)4\. Configure WAF, Bot Fight Mode, and security settings5\. Optimize Nginx reverse proxy on server for all domainsHere is my Zone-level Cloudflare API Token: [在这里粘贴你的 Token]Start now and show me the final configuration summary after completion.
使用建议:
Token 权限
:只给 Zone 级别(强烈推荐),不要给 Account 级别。
操作完成后,让 Claude 给你展示最终 DNS 配置,你再手动确认一次。
如果想让它同时部署静态文档站(doc.gaoai.co),可以在 Prompt 最后加上:“Also create a clean static mirror of docs.opusclaw.me/ at doc.gaoai.co”
安全加固必做:
防火墙只允许 Cloudflare IP 访问
关闭不必要端口
开启 Fail2Ban 等工具
进阶:Workers 智能分流(CF付费才能用,就分享给你们看看)
以下为付费专享内容,包含完整 Workers 代码。
Workers 可以在 Cloudflare 边缘节点运行代码,实现智能路由。
创建 Workers 步骤
进入 Cloudflare → Workers & Pages → 创建 Worker
粘贴以下代码:
JavaScript
addEventListener('fetch', event => { event.respondWith(handleRequest(event.request))})async function handleRequest(request) { const url = new URL(request.url); let target = "cdn.cdn.example.net"; // 默认 if (url.hostname.includes("shop")) target = "cdnshop.cdn.example.net"; if (url.hostname.includes("docs")) target = "cdndocs.cdn.example.net"; const targetUrl = `https://${target}${url.pathname}${url.search}`; return fetch(targetUrl, { method: request.method, headers: request.headers, body: request.body, redirect: "follow" });}
- 部署后绑定路由 example.com/* 和 .example.com/
Workers 架构示意图:

Cloudflare Workers Explained: Your First Step into Serverless Edge Computing | Build AI-Powered Software Agents with AntStack | Scalable, Intelligent, Reliable
实际效果
真实服务器 IP 几乎无法被直接扫描
国内访问速度提升约 3 倍(200~500ms)
DDoS 和恶意攻击被 Cloudflare 大部分拦截
认知提升
Cloudflare 真正的价值,在于你怎么调度流量。 双域名 + Workers 让你把免费的全球网络玩出高级感。
手动配置适合你完全掌控每一步,而用 Claude Code + MCP 可以实现一键式自动化,极大提升效率。
我现在基本是 手动打底 + AI 自动 的组合,既安全又省心。
你目前是用手动配置 Cloudflare,还是已经尝试让 AI 帮你部署了?欢迎评论区交流你的玩法。
最后一句狠话:
服务器 IP 暴露一天,你就多一天被黑的风险。与其事后后悔,不如现在把配置做好。
点赞 + 在看 + 收藏,需要的时候直接回来照着操作。
波波老师2026年5月
本作品采用《CC 协议》,转载必须注明作者和本文链接
关于 LearnKu
推荐文章: