使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

  • 使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程已关闭评论
  • 9 views

对于使用 WordPress 建站的站长来说,网站速度优化一直是一个棘手的问题。然而,现在随着宝塔面板的普及,WP Super Cache + Redis 成为了最简单有效的 WordPress 速度优化方案。

WP Super Cache 是目前最高效、最简单的 WordPress 静态缓存插件之一,它可以将整个网页生成为 HTML 文件,从而显著提升 WordPress 博客的访问速度。

Redis 是一种基于内存的 Key-Value 数据库,具有更快的查询速度和更高的并发能力,可以让网站达到秒开的效果。因此,将 WP Super Cache 和 Redis 结合起来使用,可以大幅度提高 WordPress 网站的性能和用户体验。

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

1. 安装 Redis
进入宝塔面板后台管理界面→选择软件管理→运行环境→Redis→点击安装,等待完成。

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

2. 安装 PHP 的 Redis 和 Opcache 扩展
① 在宝塔面板找到 PHP 设置:

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

② 在 PHP 设置中,安装 Redis 和 Opcache 扩展。

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

3. 在 WordPress 后台中,安装 Redis Object Cache 和 WP Super Cache 插件

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

4. 设置缓存插件
① 配置 WP Super Cache
通用 - 启用缓存功能 (推荐) - 更新

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

高级 - 如图配置 - 设置完成后点击更新保存设置。

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

预缓存 - 勾选”预缓存模式(垃圾回收器已禁用。推荐。)/预缓存标签,分类以及其他。“ - 保存

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

② 配置 Redis Object Cache
Enable Object Cache(启用对象缓存)打开开关即可。

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

过一段时间有图像则缓存成功:

使用宝塔面板优化WordPress网站速度:WP Super Cache + Redis实战教程

5. 修改站点伪静态

# WP Super Cache rules.
# Designed to be included from a 'wordpress-ms-...' configuration file.

set $cache_uri $request_uri;

# 请求方式为post时不使用缓存
if ($request_method = POST) {
        set $cache_uri 'null cache';
}

if ($query_string != "") {
        set $cache_uri 'null cache';
}   

# uri包含以下内容时不使用缓存
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 'null cache';
}   

# 对登录用户或已发布评论用户不使用缓存
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
        set $cache_uri 'null cache';
}

# START MOBILE
# 如果需要在移动端禁用缓存,可以把代码前的#删掉
# if ($http_x_wap_profile) {
#        set $cache_uri 'null cache';
#}

#if ($http_profile) {
#        set $cache_uri 'null cache';
#}

#if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800)) {
#        set $cache_uri 'null cache';
#}

#if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-)) {
#        set $cache_uri 'null cache';
#}
#END MOBILE

# 如果存在缓存,则使用缓存,如果没有缓存,直接转向动态页面
location / {
     try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args ;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

配置完成后,再去 WP Super Cache 重新生成缓存。

转载自:https://blog.itluo.com/experience-guide/wordpress-speed-optimization-redis.html 特别感谢。

米粒在线
  • 本文由 发表于 2024年10月24日14:49:35
  • 转载请务必保留本文链接:https://www.miliol.org/129015.html
网站建设

宝塔面板如何安装Memcached插件来加速wordpress访问

目前网站服务器带宽比较贵,在有限的小水管带宽前提下,如何加速wordpress访问倒是个难题,蜗牛般的速度强制劝退不少访问者,但是加钱加带宽嘛,又舍不得,现在图图来教小白们如何加速wordpress前...
SEO相关

PHP默认时区无效最简单的解决方法

参考了网上很多方法,有的修改模板的配置文件,有的要修改PHP里面的时区,有的要修改WORDPRESS的配置文件,试了试都没有解决。 后台直接修改 首先,后台-设置-常规,检查一下WordP...