一个计算机技术爱好者与学习者

0%

Cloudflare配置概述

1. 添加域名

  1. Create a Cloudflare account and add your domain.

  2. Choose Plan.

  3. Change your nameservers.

2. 快速配置

快速配置地址:
https://dash.cloudflare.com/<xxx>/voidking.com/recommendations
其中 <xxx> 要改成Cloudflare自动生成的随机字符串。

  1. 提高安全性,自动HTTPS重写,始终使用HTTPS
  2. 优化性能,Brotli压缩
  3. 摘要

3. DNS记录配置

Cloudflare的DNS记录配置,支持两种解析方式:

  • 仅DNS:和其他域名服务器一样,域名解析到指定的地址;
  • 代理:通过Cloudflare代理真实服务器的流量,也就是说域名解析到的地址是代理地址,真实地址会被隐藏。

解析方式是代理的情况下,就可以防DDoS了,因为代理服务器是防DDoS的,黑客攻击不到我们的真实地址。

4. 配置域名重定向

  1. 登录 Cloudflare 控制台

  2. 进入Rules,Page Rules

  3. 创建页面规则

  • URL 字段输入旧域名的匹配模式,例如:olddomain.com/*
  • Pick a Setting 选择 Forwarding URL
  • Select status code 选择 301 - Permanent Redirect
  • Enter destination URL 输入新域名,例如:https://newdomain.com/$1$1 保留原路径)
  1. 保存并部署(通常几分钟内生效)

  2. 确保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. 添加域名

  1. Create a Cloudflare account and add your domain.

  2. For your Plan, choose Business or Enterprise.

  3. Add your domain to Cloudflare. You should land on the Overview page.

  4. Ignore the instructions to change your nameservers.

  5. 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. 添加解析

  1. In Cloudflare, add an A, AAAA, or CNAME record.

  2. 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

  • 本文作者: 好好学习的郝
  • 原文链接: https://www.voidking.com/dev-cloudflare-config/
  • 版权声明: 本文采用 BY-NC-SA 许可协议,转载请注明出处!源站会即时更新知识点并修正错误,欢迎访问~
  • 微信公众号同步更新,欢迎关注~