# 通过Cloudflare API进行CDN刷新 ## 1.Cloudflare CDN刷新说明 1.Cloudfalre同Akamai一样,只有刷新,没有预热的概念。 2.通过Cloudflare API进行刷新,需要用到登录用户的\[邮箱\]\[api密钥\]\[区域ID\]。 ## 2.获取API授权 ## 2.1 获取API密钥X-Auth-Key 注:Cloudfalre的API密钥是每个账户有自己的API密钥。   ## 2.2 查看区域ID  ## 3.通过API进行刷新 **示例** ### Cloudflare CDN相关api的文档 - [https://api.cloudflare.com/#getting-started-requests](https://api.cloudflare.com/#getting-started-requests) - [https://api.cloudflare.com/#zone-purge-all-files](https://api.cloudflare.com/#zone-purge-all-files) - [https://api.cloudflare.com/#zone-purge-files-by-url](https://api.cloudflare.com/#zone-purge-files-by-url) - [https://api.cloudflare.com/#zone-purge-files-by-cache-tags,-host-or-prefix](https://api.cloudflare.com/#zone-purge-files-by-cache-tags,-host-or-prefix) ### 调用API针对文件刷新 ```bash curl -X POST "https://api.cloudflare.com/client/v4/zones/2869xxxxxxxxxxxxe1c3(区域ID)/purge_cache" \ -H "X-Auth-Email: xx@xx.jp" -H "X-Auth-Key: f2cdcdb9xxxxxxxxxx7f1072(API密钥)" \ -H "Content-Type: application/json" \ --data '{"files":["https://www.baidu.com/HotfixAssets/Global_CBT/1.5.2076/Android/2/hot_depend_tex_lightmap-0_comp_light.ab"]}' ``` ### 调用API针对目录刷新 ```bash curl -X POST "https://api.cloudflare.com/client/v4/zones/2869xxxxxxxxxxxxxxe1c3(区域ID)/purge_cache" \ -H "X-Auth-Email: xx@xx.jp" \ -H "X-Auth-Key: f2cdcdb9xxxxxxxxxxxxxxx97f1072(API密钥)" \ -H "Content-Type: application/json" \ --data '{"prefixes":["www.baidu.com/HotfixAssets/Global_OBT/6.3.6000/Android/3/"]}' ``` ### 预热,执行预热后会在全球一级节点进行预热 ```bash #!/bin/bash curl -I http://www.example.com/1.txt >> log.txt ``` 也可以这样: url放在一个文件 `file.txt`: ```bash url="http://www.google.de" url="http://www.yahoo.de" url="http://www.bing.de" ``` 然后做 ```bash curl -K file.txt -svo /dev/null ``` ## 4.通过API刷新CDN频率限制 Rate limiting:The Cloudflare API sets a maximum of 1,200 requests in a five minute period. **5分钟1200次** ## 快照 - https://pic.rmb.bdstatic.com/bjh/241107/477b38bf1eea083ae7d876de078d946b8254.png - https://i3.wp.com/pic.rmb.bdstatic.com/bjh/241107/477b38bf1eea083ae7d876de078d946b8254.png - https://788910.xyz/api/snapshot?p=2d7e5262b5727c582f901c7f33627449&u=https://pic.rmb.bdstatic.com/bjh/241107/477b38bf1eea083ae7d876de078d946b8254.png