github Page博客速度优化+Cloudflare_https两端配置+解决重定向次数过多问题

网站加速调优

自从加了CDN之后我的博客偶尔会报错”重定向次数过多“

症状:

XXX.XXX.XXX 将您重定向的次数过多。
尝试清除 Cookie.
ERR_TOO_MANY_REDIRECTS
在这里插入图片描述

可能原因

在这里插入图片描述
在这里插入图片描述

  • 参考阿里云cdn解决方案https://help.aliyun.com/document_detail/451418.html
  • 但是cloudflare中并无类似解决方案,排查CDN中ssl相关的,还有github.io设置
  • 众所周知,github.io 的ssl证书自动给你续签。
    在这里插入图片描述
  • 也有可能301被cdn缓存,https://developer.aliyun.com/article/749187
    在这里插入图片描述

尝试解决

cloudflare CDN 中的https/ssl开启,github.io中的enforce https勾选不了
参考 https://gist.github.com/cvan/8630f847f579f90e0c014dc5199c337b
在这里插入图片描述

cloudflare page rule 设置参考文档https://support.cloudflare.com/hc/en-us/articles/218411427-Is-there-a-tutorial-for-Page-Rules-

  • 意思就是说,浏览器先请求cdn,但cdn只希望从客户端获取https的请求(page rule使用https redirect),于是重定向的过程到不了github.io 因此也就没必要再enforce https。
    在这里插入图片描述在这里插入图片描述试了还是不行
    最终找到以下博客,完美解决以上系列问题

最终方案

参考

https://siriusq.top/github-pages-%E5%90%AF%E7%94%A8-cloudflare-%E5%8A%A0%E9%80%9F%E5%8F%8A-https.html

在这里插入图片描述edge端开启alway use https 和Opportunistic Encryption(HTTP/2的新特性)

在这里插入图片描述在这里插入图片描述

origin server端开启源端认证

在这里插入图片描述把上图proxied先全部改为dns only,再回github page刷新

在这里插入图片描述之后可以启用cdn的严格ssl模式
在这里插入图片描述在这里插入图片描述
然后再回去把云朵都变黄,流量通过CF即可


改天再试试cloudflare Page,据说节点更好用一些https://hee.ink/p/%E4%BB%8E-github-pages-%E8%BF%81%E7%A7%BB%E5%88%B0-cloudflare-pages-%E7%9A%84%E4%BD%93%E9%AA%8C%E4%B8%8E%E8%B8%A9%E5%9D%91%E5%B0%8F%E8%AE%B0/


速度测试

在这里插入图片描述
在这里插入图片描述
速度实在是惨不忍睹,,,


速度分析

https://www.webpagetest.org/video/compare.php?tests=230113_BiDcCR_694-r:1-c:0
在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述在这里插入图片描述

  • 境外的测试网站(https://www.webpagetest.org/),境内阿里云的图床,而且个别图片高达1MB多

测试网站性能的工具

https://putong.one/speed-test.html
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述在这里插入图片描述
在这里插入图片描述在这里插入图片描述
然而桌面端却好一倍,在这里插入图片描述在这里插入图片描述https://developers.google.com/speed/pagespeed/insights/ 以上图片来源于此站点测试
主要还是图片大小问题了


优选CF IP https://github.com/badafans/better-cloudflare-ip

CF CDN缓存配置

cloudflare cf cdn默认只缓存2个小时,提示REVALIDATED,或者EXPIRED如何修改HIT时长,缓存哪些扩展名文件?302 404缓存时间,自定义页面规则

用了一段时间cf,发现经常提示REVALIDATED,,基本上几个小时就一次,然后要回源判断文件是否更新,要不然就是EXPIRED提示文件缓存已经到期。

根据官方文章表明,只缓存2小时
200 301 120m;
302 303 20m;
403 5m;
404 5m;
any 0s;
https://support.cloudflare.com/hc/en-us/articles/202775670
说可以通过服务器输出Cache-Control: s-maxage=200,头部来告诉CDN缓存多长时间在节点上,不过我没测试。

If the URL matches: By using the asterisk (*) character, you can create dynamic patterns that can match many URLs, rather than just one. Learn more
https://support.cloudflare.com/hc/en-us/articles/218411427

页面规则写,不要带http或者https,这样写法是整个域名包括所有二级域名都生效
example.com/
复制代码

Edge cache ttl改成一个月,也就是672h0m0

这样就可以缓存长达一个月的时间啦!

参考写法
example.com/static/
[/static/ subdirectory for static HTML pages]

example.com/.shtml
[.shtml file extension to signify HTML that is static]

example.com/?static=true
[adding static=true query parameter]

如果Cache-Control标头设置为“private”,“no-store”,“no-cache”或“max-age = 0”,或者如果响应中有cookie,则Cloudflare将不会缓存资源,除非将页面规则设置为缓存所有内容并设置了边缓存TTL。
https://support.cloudflare.com/hc/en-us/articles/200172256

cloudflare默认提供缓存哪些扩展名文件?
bmp ejs jpeg pdf ps ttf
class eot jpg pict svg webp
css eps js pls svgz woff
csv gif mid png swf woff2
doc ico midi ppt tif xls
docx jar otf pptx tiff xlsx
https://support.cloudflare.com/hc/en-us/articles/200172516

cloudflare cf CDN 使用服务条款 tos帮助页面,是否允许缓存视频,音频文件
https://bbs.itzmx.com/forum.php?mod=viewthread&tid=94372&fromuid=1

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值