GitHub Pages 因 Cloudflare DNS 无法正常启用强制 HTTPS

起因

因为 Cloudcone 服务器被停掉之后就着手开始了 GitHub Pages + Hexo 的摸索,在测试过程中发现,不知道为什么无法正常开启 Enforce HTTPS(强制HTTPS),根据 GitHub 提供的内容,发现自己的配置是完全没有任何问题的。那么问题出在了哪里呢?

研究

Troubleshooting Custom Domains 的内容:

HTTPS errors
GitHub Pages sites using custom domains that are correctly configured with CNAME, ALIAS, ANAME, or A DNS records can be accessed over HTTPS. For more information, see “Securing your GitHub Pages site with HTTPS.”
It can take up to an hour for your GitHub Pages site to become available over HTTPS after you add and correctly configure your custom domain. After updating existing DNS settings, you may need to remove and re-add your custom domain to your GitHub account to trigger the process of enabling HTTPS. For more information, see “Using a custom domain with GitHub Pages.”
If you’ve chosen to use Certification Authority Authorization (CAA) records, at least one CAA record must exist with the value letsencrypt.org for your GitHub Pages site to be accessible over HTTPS. For more information, see “Certificate Authority Authorization (CAA)” in the Let’s Encrypt documentation.
Custom domains configured with A records
If you configured your custom domain using an A record, your A record must point to one of the following IP addresses for HTTPS to work:
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
After updating any A record IP addresses, you must remove and re-add your custom domain to the repository you’re using to publish your Pages site to trigger the process of enabling HTTPS. For more information, see “Configuring A records with your DNS provider” in “Setting up an apex domain.”

仔细查看其内容,结合经验,不难发现,其他的配置是完全达标的,但是其中有一点,便是申请证书。
申请证书时,他会检测你的DNS指向的目标是否和申请的一致,例如我的 GitHub 页面正常会指向 nitu2003.github.io,但是经过 Cloudflare CDN 之后变成了他的服务器,所有导致检测错误,无法申请到证书,自然不能开启 Enforce HTTPS

解决

解决方法非常简单,先将 Cloudflare DNS 中的 Status 选项从 DNS and HTTP proxy (CDN) 改为 DNS Only
等待一小会,让 GitHub pages 在此申请证书,便可以得到正确的结果,然后就可以开启 Enforce HTTPS 了。
启动之后再回到 Cloudflare DNSStatus 改回 DNS and HTTP proxy (CDN) 即可。