wordpress网站Waiting(TTFB)时间过长,Cachify插件实现网站加速方法

2023-02-0910:39:35网站建设与开发Comments883 views字数 1504阅读模式

日访问IP5万左右,服务器32G16H,有CDN,开启了Memcached,前端访问非常快,后端登录后很慢,Waiting(TTFB)时间基本上在1分钟左右,通过各种检查,发现实际上还是有很多优化的空间。比如缓存加速,直接把内容缓存到内存当中去,进行网站加速。这里博主就介绍一下利用Cachify插件实现网站加速, Cachify插件可以说是wordpress必备的插件之一了,对于这个站提速非常明显。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

wordpress网站Waiting(TTFB)时间过长,Cachify插件实现网站加速方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

Cachify缓存插件描述文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

Cachify 通过将文章,页面和存档页面缓存为静态内容来优化页面加载。我们可以根据需要选择把静态内容缓存到 WordPress 数据库,硬盘,APC(PHP 缓存)或者 Memcached 中。用户再次访问页面时,直接从缓存中读取页面给用户,不用再查询数据库了。真正的做到了数据库0查询。它能够有效缩短TTFB 时间过长,甚至优化的50ms以内。Cachify 插件只会缓存用户访问过的页面,长时间没有用户再次访问的页面,Cachify 会从缓存中把这个页面清除掉,确保缓存高效。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

Cachify缓存插件的特性文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

适用于自定义文章类型。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

缓存方法:DB,HDD,APC 和 Memcached。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

通过 WordPress 工具栏中的 “刷新缓存” 按钮删除缓存。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

支持 WordPress 多站点。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

可以选择压缩 HTML 或 JavaScript。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

可以为用户浏览器和文章设置不缓存。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

手动和自动删除缓存。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

自动缓存管理。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

可以查看缓存状态的仪表板小部件。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

Apache 和 Nginx 服务器的设置。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

通过钩子/过滤器扩展插件。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

Cachify 插件只会缓存用户访问过的页面,长时间没有用户再次访问的页面,Cachify 会从缓存中把这个页面清除掉,确保缓存高效。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

1、首先确认服务器支持 Memcached文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

这里以宝塔面版为例,启用PHP的 Memcached 扩展。这里是已经启用的状态。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

wordpress网站Waiting(TTFB)时间过长,Cachify插件实现网站加速方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

2、然后下载Cachify插件安装启用文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

到Wordpress后台直接搜索Cachify插件即可安装,并点击启用文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

wordpress网站Waiting(TTFB)时间过长,Cachify插件实现网站加速方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

启用Cachify插件后界面如下图,配置自行参考 :文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

wordpress网站Waiting(TTFB)时间过长,Cachify插件实现网站加速方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

3、保存后再写代码文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

以宝塔面版为例,Nginx 配置文件中添加以下配置,重启 Nginx。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

#宝塔面板直接在网站的伪静态规则里修改即可。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

location / {文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

#注释掉原有的规则文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

#try_files $uri $uri/ /index.php?$args;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

#启用Cachify开始文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

error_page 404 405 = @nocache;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

if ( $query_string ) {文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

return 405;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

if ( $request_method = POST ) {文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

return 405;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

if ( $request_uri ~ "/wp-" ) {文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

return 405;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

if ( $http_cookie ~ (wp-postpass|wordpress_logged_in|comment_author)_ ) {文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

return 405;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

default_type text/html;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

add_header X-Powered-By Cachify;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

set $memcached_key $host$uri;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

memcached_pass 127.0.0.1:11211;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

#启用Cachify结束文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

#启用Cachify开始文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

location @nocache {文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

try_files $uri $uri/ /index.php?$args;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

#启用Cachify结束文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

#以下为原配置规则,继续保留文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

rewrite /wp-admin$ $scheme://$host$uri/ permanent;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

如下图:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

wordpress网站Waiting(TTFB)时间过长,Cachify插件实现网站加速方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

现在重新加载一下网站,看看waiting ttfb加载时长。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

以下是本站ctrl+F5强制刷新的效果文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

wordpress网站Waiting(TTFB)时间过长,Cachify插件实现网站加速方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

本文来源:廖维林博客文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/30780.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/30780.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定