
Cache Enabler 外挂是KeyCDN 开发的一款WordPress 轻量级快取插件,创建静态HTML 文件并将其存储在服务器硬盘上,Web 服务器将传递静态HTML 文件给你的网站读者,可以避免太密集的进程在服务器后端(CPU、插件和数据库),并提高你的WordPress 网站的性能,有效加速网站速度,而且是完全免费。
说道Cache Enabler插件,就会提到德国非常受欢迎的Cachify快取插件,但是作者似乎放弃更新,程式码写得很好,轻量且高效能。Cache Enabler插件就是以Cachify为原型,加以改良,增加了WebP图片优化,更与Autoptimize有完美的结合。
Cache Enabler 配置的方法非常容易,启动插件后,依照预设的配置就可以,如个你还不满意这样的快取模式,可以修改Nginx 的conf 文件,完全绕过PHP 程序,达到快取型态。
安装Cache Enabler插件:https://wordpress.org/plugins/cache-enabler/
Cache Enabler Plugin 高级配置
复制/etc/nginx/common/php.conf 文件,给予一个新名称,例如:wpcache.conf
打开wpcache.conf 文件,修改如下:
44 # PHP NGINX CONFIGURATION
# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE Webinoly
set $cache_uri $request_uri;
# bypass cache if POST requests or URLs with a query string
if ($request_method = POST) {
set $cache_uri 'nullcache';
}
if ($query_string != "") {
set $cache_uri 'nullcache';
}
# bypass cache if URLs containing the following strings
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $cache_uri 'nullcache';
}
# bypass cache if the cookies containing the following strings
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'nullcache';
}
# custom sub directory e.g. /blog
set $custom_subdir '';
# default html file
set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index.html';
# webp html file
if ($http_accept ~* "image/webp") {
set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index-webp.html';
}
location / {
gzip_static on; # this directive is not required but recommended
try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass php;
}
存档后,上传至/etc/nginx/common 资料夹内。
修改你的虚拟主机的conf 文件
打开/etc/nginx/sites-available/example.com 文件,将php.conf 更换为wpcache.conf,如下
include common/wpcache.conf;
include common/wpcommon.conf;
include common/locations.conf;
include common/headers-http.conf;
include common/headers-html.conf;
include common/headers-https.conf;
存档后重启Nginx
nginx -t && service nginx restart
结语
默认的Cache Enabler 设置将满足大部分的使用情况。您不必再添加自定义代码配置在Nginx 上,也不需要设置cron 作业。
多增加这个配置,以我目前的网站是感觉不出有什么不同,可能需要一个高流量网站来测试,会比较准确。
人吐槽 | 人点赞 |
发表评论