类别: 建站技术

解决通过CNAME方式接入CloudFlare后无法使用Super Page Cache for Cloudflare的问题

概述

通过CNAME方式接入Cloudflare后,使用Super Page Cache for Cloudflare插件清除缓存时报错 An error occurred while cleaning the cache. Please check log file for further details. 我们只需在设置Cloudflare Domain Name 选项时,通过浏览器的开发者工具修改select选项中value值为cname指向域名的CF Zone ID值即可。

问题描述

我的前文博客中介绍了通过CNAME方式接入Cloudflare(配置方法见另一篇博客),但是通过这种方式接入后,若要使用Super Page Cache for Cloudflare(CF专门为WP开发的用于开启页面缓存的官方插件)就会出现问题,报错 An error occurred while cleaning the cache. Please check log file for further details. ,查看debug日志文件,发现错误信息为 [2024-02-28 16:28:30] [cache_controller::purge_urls] Unable to purge some URLs from Cloudflare due to error: Authentication error (err code: 10000)

Super Page Cache for Cloudflare清除单页缓存时报错

问题原因

为了方便理解,先简单介绍一下前文“通过CNAME方式接入Cloudflare”,文中提到:有一个域名A(www.a.com)需要通过CNAME方式接入CloudFlare CDN,而NS服务器(域名解析服务器)采用阿里云或者其他的。我们手中有一个域名B(bluepost.cn)已经开启CloudFlare,并且CF账号已开启CloudFlare for SaaS功能。

该问题的原因是:通过Cname方式接入Cloudflare后,再去配置Super Page Cache for Cloudflare,使用的域名是该域名的Cloudflare Zone ID(即前文博客中提到的A域名),而这里我们需要设置 Cloudflare Domain Name 选项为 B域名(即设置cname时指向的域名bluepost.cn)的Cloudflare Zone ID,而设置项select选项中没有B域名的选项,这时就需要采取其他方法设置 Cloudflare Domain Name 选项。

解决方法

知道了问题原因,解决方法也很简单。我们首先需要选择Authentication mode为API Key,并填写设置项,最后在设置Super Page Cache for Cloudflare 的 Cloudflare Domain Name 选项时,先选择下拉框中的任一域名(一般只有该网站的域名)。然后再打开浏览器的“开发者工具”(按F12即可打开该工具),找到Cloudflare Domain Name 配置项的select元素,将选项的select的value值改为B域名的Zone ID,然后我们保存设置,之后再次清理缓存时,就不会报错了。

Super Page Cache for Cloudflare插件设置界面,请按照图中所示填入自己的值
修改Cloudflare Domain Name 配置项的select下拉框选中项的value值为cname指向域名的CF Zone ID

Super Page Cache for Cloudflare操作中的debug日志解读

[2024-02-28 16:27:42] [cache_controller::ajax_purge_whole_cache] Purge whole Cloudflare cache
[2024-02-28 16:27:42] [cache_controller::purge_all] Unable to purge the whole Cloudflare cache due to error: Authentication error (err code: 10000)
[2024-02-28 16:27:49] [cache_controller::purge_urls] Unable to purge some URLs from Cloudflare due to error: Authentication error (err code: 10000)
[2024-02-28 16:28:30] [cache_controller::purge_urls] Unable to purge some URLs from Cloudflare due to error: Authentication error (err code: 10000)
[2024-02-28 16:31:59] [cache_controller::purge_urls] Purged specific URLs from Cloudflare cache
[2024-02-28 16:31:59] [cache_controller::ajax_purge_single_post_cache] Purge Cloudflare cache for only post id 7805 and related contents

从日志中可以看出来,Super Page Cache for Cloudflare 选择A域名(该网站域名)作为CF Zone ID 时,16:27清除全部缓存失败(虽然操作时提示界面未成功,但实际未成功)报错Unable to purge the whole Cloudflare cache due to error: Authentication error (err code: 10000),16:28清除单页缓存失败报错Unable to purge some URLs from Cloudflare due to error: Authentication error (err code: 10000)

再按照上述解决方法,设置B域名(cname指向域名bluepost.cn)作为CF Zone ID,16:31清除单页缓存成功。

修改select选中项的value值后,再次清理缓存成功

【相关文章】通过CNAME方式接入Cloudflare

转载请注明:半亩方塘 » 解决通过CNAME方式接入CloudFlare后无法使用Super Page Cache for Cloudflare的问题