Warning: Cannot use bool as array in /opt/ace/sites/blog_ciy_cool/usr/plugins/AMP/Action.php on line 587

Warning: Cannot use bool as array in /opt/ace/sites/blog_ciy_cool/usr/plugins/AMP/Action.php on line 587

Warning: Cannot use bool as array in /opt/ace/sites/blog_ciy_cool/usr/plugins/AMP/Action.php on line 587

Warning: Cannot use bool as array in /opt/ace/sites/blog_ciy_cool/usr/plugins/AMP/Action.php on line 587
Typecho使用Cloud flare缓存加速访问

MakotoArai

Typecho使用Cloud flare缓存加速访问

Typecho使用Cloud flare缓存加速访问

事件起因

博客使用Typecho建站也有一年多了,因为没啥访问量,我就没有去做什么优化,半年之前我都是服务器裸奔,访问是真的快,除了一些图片加载确实非常慢。这个问题可以用CDN解决,免费方案就只有Cloud flare,国内其他的服务商都是收费的,搞不好一夜睡醒就欠一栋房了。但是Cloud flare在国外,访问自然不会很快,但是CDN效果还是有的,肯定比裸奔效果更强。当时我把域名解析到Cloud flare了,但是不会配置,博客加载出奇的慢。

直到我被大学校友爬了……这太可怕了,他能轻易抓到我网站的很多数据啊。再狠一点,可能没几天服务器都不是我的了。啧,又套了Cloud flare。随便学了一点,虽然速度和之前一样很慢,但是博客还是比之前要安全了。博客没什么访问量,快慢无伤大雅。

终于到前几天,友链开始变多了,这必须优化优化。翻了很多帖子和博客,最终找到明月登楼的这套方案,对比之前相当快。

操作过程

1. 打开配置界面

  1. 打开Cloud flare官网,点击右上角的登录,进入Cloud flare的登录页登录你的账号。(没有账号请自行注册)
  2. 登录后会自动跳转账户主页
  3. 点击你的域名进入域名配置页面,在左边的菜单找到缓存(caching)-->Cache Rules

2. 配置缓存规则

1. 配置不缓存规则

(starts_with(http.request.full_uri, "https:/blog.example.com/admin/")) or (starts_with(http.request.full_uri, "https:/blog.example.com/search/")) 

2. 配置登录和评论缓存规则

(starts_with(http.request.full_uri, "https://blog.example.com/") and http.cookie contains "__typecho_authCode" and http.cookie contains "__typecho_uid") or (starts_with(http.request.full_uri, "https://blog.example.com/") and http.cookie contains "__typecho_remember_")

3. 配置全局缓存规则

(starts_with(http.request.full_uri, "https://blog.example.com/") and not http.cookie contains "__typecho_authCode" and not http.cookie contains "__typecho_uid" and not http.cookie contains "__typecho_remember_") or (starts_with(http.request.full_uri, "https://blog.example.com/usr/uploads"))

3. 检查规则顺序

缓存规则一定不能错,错了没有效果

4. 查看缓存命中率

打开树形菜单的分析和日志-->HTTP 流量就能看到啦

总结

整体效果还是很好的,无论是国内、国外请求都能秒开,站内链接切换也都是秒开。缺点是文章会缓存7天,发布文章或者重新编辑某个文章后因为缓存周期设置缘故造成首页或者编辑过的文章不能实时更新,需要手动清除缓存。

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »