ngx_pagespeed 配合Cachify缓存插件,把 WordPress 页面缓存到 Memcached 中,让网页瞬间打开
1 2 | https://www.wpzhiku.com/cachify/ https://www.linpx.com/p/not-enough-with-the-ngxpagespeed-configuration-tutorial.html/comment-page-1 |
1. 安装memcached
https://lnmp.org/faq/addons.html
1 2 3 | sudo su cd /root/lnmp1.6 ./addons.sh install memcached |
2. 查看是否已成功
1 2 | systemctl restart nginx systemctl status nginx |
1 | sudo reboot |
http://34.94.62.53/vphpinfo.php 的显示memcached信息说明已经成功
3. 优化配置
1 | sudo vi /usr/local/nginx/conf/vhost/chinastonetops.com.conf |
在pagespeed on; 下添加memcached的配置
1 2 | pagespeed MemcachedThreads 1; pagespeed MemcachedServers "localhost:11211"; |
1 2 | systemctl restart nginx systemctl status nginx |
4. 在站点的 Nginx 配置文件中添加以下配置,重启 Nginx
1 | sudo vi /usr/local/nginx/conf/vhost/chinastonetops.com.conf |
4-1. 删掉第10行及第201行” include rewrite/wordpress.conf “,否则会相冲突,Nginx会无法启动
[Cachify 的配置代码和第 10 行中 include 的 WordPress 的配置代码冲突了,
把 include 这一行去掉,然后 WordPress 的配置代码合并到 cachify 配置代码中就可以了]
10 include rewrite/wordpress.conf; //http
201 include rewrite/wordpress.conf; //https
4-2. 然后把如下代码加到158行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | location / { error_page 404 405 = @nocation; 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; } |
1 2 3 | systemctl stop nginx systemctl restart nginx systemctl status nginx |
总算成功
3. WordPress后台安装Cacify插件
1. 插件下载地址:
https://webcode.chinastonetops.com/wordpress/plugin/
2. 安装并激活插件: Plugins – add new – upload plugin – install now – activate
3. Settings – Cachify
Cache method Memcached
Cache expiration 168 Hours
Cache generation 两个都打勾
Cache exceptions 空着
Cache minify HTML + Inline JavaScripts
点击”保存更改[Save Changes]”
现在你可以退出登录,重新加载一下网站,看看waiting ttfb加载时长。
以下是本站ctrl+F5强制刷新的效果,是不是很快?