wp博客搬家之后出现ttfb时间过长的解决办法,把页面缓存进内存就好了,先安装Memcached
在网站根目录下的 wp-config.php 中添加如下语句开启缓存:
/** 激活Memcached */
define(‘ENABLE_CACHE’, true);
/** 激活Batcache */
define(‘WP_CACHE’, true);
做到以上两点之后,我们需要对站点的 Nginx 配置文件中添加以下配置,重启 Nginx。
下面这段代码放在配置文件最后的一个括号前的
location ~ / {
error_page 404 405 = @nocache;
if ( $query_string ) {
return 405;
}
if ( $request_method = POST ) {
return 405;
}
if ( $request_uri ~ “/wp-” ) {
return 405;
}
if ( $http_cookie ~ (wp-postpass|wordpress_logged_in|comment_author)_ ) {
return 405;
}
default_type text/html;
add_header X-Powered-By Cachify;
set $memcached_key $host$uri;
memcached_pass localhost:11211;
}
location @nocache {
try_files $uri $uri/ /index.php?$args;
}
然后在wordpress插件里搜索 Cachify 下载安装并启用。我的配置如下: 硬盘模式 2000小时 html+js
define(‘DB_NAME’, ‘xiaoyaohou_com’);
/** MySQL数据库用户名 */
define(‘DB_USER’, ‘root’);
/** MySQL数据库密码 */
define(‘DB_PASSWORD’, ‘Chumima1@lm’);
/** MySQL主机 */
define(‘DB_HOST’, ‘sh-cdb-4i9g7sdn.sql.tencentcdb.com:63289’);
评论前必须登录!
注册