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 for SaaS配置
4.1. 添加域名
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.
4.2. 验证域名
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.
4.3. 添加解析
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.
5. CloudFlare的坑
使用CloudFlare作为代理后,真实后端响应时间必须在100s以内,否则会报错524。
解决办法是升级企业版,详情参考Troubleshooting Cloudflare 5XX errors – Cloudflare Help Center