1. 添加域名
Create a Cloudflare account and add your domain.
Choose Plan.
Change your nameservers.
2. 快速配置
快速配置地址:https://dash.cloudflare.com/<xxx>/voidking.com/recommendations
其中 <xxx>
要改成Cloudflare自动生成的随机字符串。
- 提高安全性,自动HTTPS重写,始终使用HTTPS
- 优化性能,Brotli压缩
- 摘要
3. DNS记录配置
Cloudflare的DNS记录配置,支持两种解析方式:
- 仅DNS:和其他域名服务器一样,域名解析到指定的地址;
- 代理:通过Cloudflare代理真实服务器的流量,也就是说域名解析到的地址是代理地址,真实地址会被隐藏。
解析方式是代理的情况下,就可以防DDoS了,因为代理服务器是防DDoS的,黑客攻击不到我们的真实地址。
4. 配置域名重定向
登录 Cloudflare 控制台
进入Rules,Page Rules
创建页面规则
- URL 字段输入旧域名的匹配模式,例如:
olddomain.com/*
- Pick a Setting 选择 Forwarding URL
- Select status code 选择 301 - Permanent Redirect
- Enter destination URL 输入新域名,例如:
https://newdomain.com/$1
($1
保留原路径)
保存并部署(通常几分钟内生效)
确保DNS记录正确
旧域名需在 DNS 中添加一条 A记录(如@
或www
),IP可随意(如192.0.2.1
或者8.8.8.8
),但必须开启 代理(橙色云图标)。
5. CloudFlare for SaaS配置
5.1. CloudFlare for SaaS简介
CloudFlare for SaaS允许未直接使用 Cloudflare NS 的域名仍可享受CloudFlare CDN 和安全服务,需要商业版或者企业版才能支持。
5.2. 添加域名
Create a Cloudflare account and add your domain.
For your Plan, choose Business or Enterprise.
Add your domain to Cloudflare. You should land on the Overview page.
Ignore the instructions to change your nameservers.
For Advanced Actions, click Convert to CNAME DNS Setup.
5.3. 验证域名
Once you add your domain to Cloudflare, add the Verification TXT Record at your authoritative DNS provider. Cloudflare will verify the TXT record and send a confirmation email. This can take up to a few hours.
5.4. 添加解析
In Cloudflare, add an A, AAAA, or CNAME record.
At your authoritative DNS provider:
a. Remove any existing A, AAAA, or CNAME records on the hostname you want to proxy to Cloudflare.
b. Add a CNAME record for {your-hostname}.cdn.cloudflare.net.
c. Repeat this process for each subdomain proxied to Cloudflare.
6. 问题记录
6.1. 后端响应时间限制
使用CloudFlare作为代理后,真实后端响应时间必须在100s以内,否则会报错524。
解决办法是升级企业版,详情参考Troubleshooting Cloudflare 5XX errors – Cloudflare Help Center