[教程] 基于Redis Object Cache和WP Super Cache的wordpress缓存方案(速度优化)

查看: 526|回复: 2
crll 发表于 2023-3-20 21:35:29
1.安装redis
过程不再赘述。

2.安装php的redis和opcache扩展


3.安装wordpress的Redis Object Cache和WP Super Cache缓存插件



4.设置缓存插件
(1)WP Super Cache

按照图示进行设置即可:




设置完成后点击更新保存设置。
接下来配置预缓存:

检查是否生效:

有内容则缓存成功:(没有内容也不用着急,继续往下做)



值得注意的是:一定要开启专家模式而不是普通模式,经测试,普通模式会与接下来要配置的redis插件冲突!

(2)Redis Object Cache
打开开关即可:


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


5.修改站点伪静态
  1. # WP Super Cache rules.
  2. # Designed to be included from a 'wordpress-ms-...' configuration file.
  3. set $cache_uri $request_uri;
  4. # 请求方式为post时不使用缓存
  5. if ($request_method = POST) {
  6.         set $cache_uri 'null cache';
  7. }
  8. if ($query_string != "") {
  9.         set $cache_uri 'null cache';
  10. }   
  11. # uri包含以下内容时不使用缓存
  12. 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)") {
  13.         set $cache_uri 'null cache';
  14. }   
  15. # 对登录用户或已发布评论用户不使用缓存
  16. if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
  17.         set $cache_uri 'null cache';
  18. }
  19. # START MOBILE
  20. # 如果需要在移动端禁用缓存,可以把代码前的#删掉
  21. # if ($http_x_wap_profile) {
  22. #        set $cache_uri 'null cache';
  23. #}
  24. #if ($http_profile) {
  25. #        set $cache_uri 'null cache';
  26. #}
  27. #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)) {
  28. #       set $cache_uri 'null cache';
  29. #}
  30. #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-)) {
  31.   #      set $cache_uri 'null cache';
  32. #}
  33. #END MOBILE
  34. # 如果存在缓存,则使用缓存,如果没有缓存,直接转向动态页面
  35. location /
  36. {
  37.      try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args ;
  38. }
  39. rewrite /wp-admin$ $scheme://$host$uri/ permanent;
复制代码


配置完成后,再去WP Super Cache重新生成缓存,这样就没问题了!
博主论坛 bzlt.net
CCC 发表于 2023-3-21 12:18:05
用专家模式记得用apache,用nginx有毛病,用redis推荐配置上密码
帮主 发表于 2023-3-21 13:39:40
技术贴。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于本站联系我们FAQ友情链接免责声明生存法则

Build with for "make" Copyright © 2020-2022. Powered by Discuz! GMT+8, 2024-4-25 13:30

快速回复 返回顶部 返回列表