type
status
date
summary
tags
category
icon
背景
在阿里云购买过一个域名 donotevil.com, 因不想要这个域名,想把这个域名重定向到新购买的域名。本以为是一个很简单的事情,在阿里云的域名管理那配置一个解析规则即可,阿里云确实有这个功能,但也有一个限制,域名需要先备案,否则配置时会提示 ”域名未备案,无法添加转发。“
此路不通,想起之前使用过Cloudflare托管过域名,因此尝试使用Cloudflare进行重定向
Cloudflare托管域名
阿里云购买的域名,默认的域名解析服务器为阿里云的 dns9.hichina.com,如果需要使用Cloudflare管理域名,可以修DNS服务器为Cloudflare的。
首先在Cloudflare新增站点:
- 首页顶部点击 “新增站点” 按钮;
- 输入域名,点击 “继续” 按钮;
- 选择免费的计划,会自动解析dns的记录,解析完点击页面底部的 “继续” 按钮;
- 复制 域名服务器地址;
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9047f58e-5ddf-46fd-a4b7-6d1a8d133c25%2Fb388266f-9c2c-4d11-aa09-6d57a0f71cf3%2FUntitled.png?table=block&id=6540e089-31c1-45bd-9799-e53c387ae7f3&t=6540e089-31c1-45bd-9799-e53c387ae7f3&width=1758&cache=v2)
接下来进入阿里云的进入域名管理页面(从列表页面 https://dc.console.aliyun.com/#/domain-list/all 点击域名进入),修改DNS域名服务器:
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9047f58e-5ddf-46fd-a4b7-6d1a8d133c25%2F839cee69-fa89-46ad-ae2e-bb9b68882663%2FUntitled.png?table=block&id=095a70a7-a6be-4774-86e6-e85e4a5cbd03&t=095a70a7-a6be-4774-86e6-e85e4a5cbd03&width=1864&cache=v2)
配置好之后,然后可以回到Cloudflare查看域名是否可以正常解析。
Cloudflare添加域名解析记录
添加DNS记录,内容就是需要被解析的IP地址,可以随便填写一个公网的IP,例如公共的114DNS服务器 114.114.114.144 或者google 的DNS:8.8.8.8
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9047f58e-5ddf-46fd-a4b7-6d1a8d133c25%2Fff77c57b-d9e1-4910-a786-4e4f1907e92c%2FUntitled.png?table=block&id=a7209d1c-a07a-4052-966e-1945fb963d2f&t=a7209d1c-a07a-4052-966e-1945fb963d2f&width=2730&cache=v2)
这个步骤主要是告诉Cloudflare如何解析我们的域名,这块最后是 A 或者 AAAA 记录,试了试CNAME类型,后续重定向会失败的。
Cloudflare中添加重定向
在规则中设置一下页面的访问规则
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9047f58e-5ddf-46fd-a4b7-6d1a8d133c25%2F3f6f8ed0-78be-4bde-9a88-6924a85239b2%2FUntitled.png?table=block&id=5efbe1aa-9f2e-47dc-94a6-6133da6d893b&t=5efbe1aa-9f2e-47dc-94a6-6133da6d893b&width=2772&cache=v2)
配置如下:
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9047f58e-5ddf-46fd-a4b7-6d1a8d133c25%2F1a96ce10-e564-4993-9a2a-82eaa6ed016c%2FUntitled.png?table=block&id=c81fdb5b-bca7-415e-a4da-fabebe79ad3b&t=c81fdb5b-bca7-415e-a4da-fabebe79ad3b&width=2330&cache=v2)
然后可以保存一下,就可以测试一下配置的重定向是否生效,也可以通过 https://www.dute.org/httpstatus 测试一下不同的链接。
上面的 * 是同一个通配符,表示域名后面的路径都可以匹配,例如 donotevil.com/* ,可以匹配以下的路径:https://donotevil.com/test, https://donotevil.com 等,可以使用 $1 匹配对应位置的 * 命中的内容
总结
通过使用Cloudflare解析域名,可以绕过阿里云无法配置未备案域名重定向的情况,需要注意的是配置的时候需要先配置一个DNS解析记录,不然无法应用上页面规则。