最新消息:

WordPress 缓存插件 WP Rocket

插件 东方星雨 329浏览 0评论

WordPress 静态缓存插件有很多,比如: WP Super Cache 、 Hyper Cache 、 W3 Total Cache 、当然还有今天要介绍的 WP Rocket 插件。它们都各有各的特点,感兴趣的朋友可以百度一下,今天主要讲一讲 WP Rocket 的使用介绍。

WordPress 缓存插件 WP Rocket v2.9.2

WP Rocket

产品描述

WP Rocket 自称是当前最高效也是最灵活的 WordPress 静态缓存插件。可以优化你的 JS CSS 文件结构减少多次请求达到优化速度的目的,还集成了图片延迟加载对最求极致加速的用户不错的选择,通过使用这个插件,能使得你的 WordPress 博客将显著的提速。

WordPress 缓存插件 WP Rocket v2.9.8.1 汉化版

WordPress 缓存插件 WP Rocket v2.9.8.1 汉化版

更新日志

2.9.9 (2017年3月22日更新)

  • Enhancement: Compatibility with GoDaddy Managed Hosting
  • Enhancement: Update Mobile_Detect class to recent version
  • Enhancement: Allow caching when the ao_noptimize query string is set
  • Fix: LazyLoad Iframes & Videos no longer crashes Android Facebook browser
  • Fix: CDN URL no longer applied on SVG URL by reference
  • Fix: Remove query string is now correctly applied when minification disabled on a single post
  • Fix: Imagify install button works again

2.9.8.1 (2017年3月2日更新)

  • Regression Fix: PHP Fatal error: Can’t use function return value in write context in ../inc/front/cdn.php on line 138

WP Rocket v2.9.2(2017年1月11日)

  • Enhancement: Apply CDN URL to images displayed with wp_get_attachment_image_src()
  • Enhancement: Preserve Yandex comments during HTML minification
  • Enhancement: save CloudFlare IPs in a transient to prevent calls to the CloudFlare API
  • Fix: Replace spaces in cache busting path to prevent loading issue with the cache busting files
  • Fix: Do not minify if request is a POST method to prevent JS files to be added in the footer of a not cached page
  • Fix: Check if post type is an object before purge to prevent a PHP warning
  • Fix: Correctly remove the cache busting folder when uninstalling WP Rocket
  • Fix: Force int type for CloudFlare browser cache TTL value

关于 WP Rocket 配置

我这里主要讲 web 服务器是 Nginx 的使用方法。

1、下载安装 WP Rocket (下载地址往下看),39 刀正版支持,诸位老板少抽几包烟,尽量支持官方。

2、添加rewite规则到vhost配置文件中。目的就是让web服务器节省在请求动态文件,直接读取生成的静态文件。

  1. ###################################################################################################
  2. # Rocket-Nginx
  3. #
  4. # Rocket-Nginx is a NGINX configuration to speedup your WordPress
  5. # website with the cache plugin WP-Rocket (http://wp-rocket.me)
  6. #
  7. # Author: Maxime Jobin
  8. # URL: https://github.com/maximejobin/rocket-nginx
  9. #
  10. # Tested with WP-Rocket version: 2.8.11
  11. # Tested with NGINX: 1.11.3 (mainline)
  12. #
  13. # Version 1.2
  14. #
  15. ###################################################################################################
  16.  
  17. # Add debug information into header
  18. set $rocket_debug 0;
  19.  
  20. # HTTP Strict Transport Security (to overwrite default)
  21. set $rocket_hsts_value “”;
  22.  
  23. # WP-Content directory (leave as is if you did not alter WordPress’ default value)
  24. set $rocket_wpcontent_directory “$document_root/wp-content”;
  25.  
  26. # WP-Content URL (leave as is if you did not alter WordPress’ default value)
  27. set $rocket_wpcontent_url “/wp-content”;
  28.  
  29. ###################################################################################################
  30. # Do not alter theses values
  31. #
  32. set $rocket_bypass 1; # Should NGINX bypass WordPress and call cache file directly ?
  33. set $rocket_encryption “”; # Is GZIP accepted by client ?
  34. set $rocket_file “”; # Filename to use
  35. set $rocket_is_bypassed “No”; # Header text added to check if the bypass worked or not. Header: X-Rocket-Nginx-Bypass
  36. set $rocket_reason “”; # Reason why cache file was not used. If cache file is used, what file was used
  37. set $rocket_https_prefix “”; # HTTPS prefix to use when cached files are using HTTPS
  38. set $rocket_hsts 0; # Is HSTS is off (0) by default. Will be turned on (1) if request is HTTPS
  39.  
  40. # HSTS Default value : 1 year, include subdomains.
  41. set $rocket_hsts_value_default “max-age=31536000; includeSubDomains”;
  42.  
  43. ###################################################################################################
  44. # PAGE CACHE
  45. #
  46.  
  47. # Is GZIP accepted by client ?
  48. if ($http_accept_encoding ~ gzip) {
  49. set $rocket_encryption “_gzip”;
  50. }
  51.  
  52. # Is SSL request ?
  53. if ($https = “on”) {
  54. set $rocket_https_prefix “-https”;
  55. set $rocket_hsts 1;
  56. }
  57.  
  58. # If HSTS value is not set, use default value
  59. if ($rocket_hsts_value = “”) {
  60. set $rocket_hsts_value “$rocket_hsts_value_default”;
  61. }
  62.  
  63. # If HSTS is disabled, unset HSTS set for Rocket-Nginx configuration
  64. if ($rocket_hsts = “0”) {
  65. set $rocket_hsts_value “”;
  66. }
  67.  
  68. # File/URL to return IF we must bypass WordPress
  69. # index-mobile.html
  70. # index-mobile-https.html
  71. set $rocket_end “/cache/wp-rocket/$http_host/$request_uri/index$rocket_https_prefix.html$rocket_encryption”;
  72. set $rocket_url “$rocket_wpcontent_url$rocket_end”;
  73. set $rocket_file “$rocket_wpcontent_directory$rocket_end”;
  74. set $rocket_mobile_detection “$rocket_wpcontent_directory/cache/wp-rocket/$http_host/$request_uri/.mobile-active”;
  75.  
  76.  
  77. # Do not bypass if it’s a POST request
  78. if ($request_method = POST) {
  79. set $rocket_bypass 0;
  80. set $rocket_reason “POST request”;
  81. }
  82.  
  83. # Do not bypass if arguments are found (e.g. ?page=2)
  84. if ($is_args) {
  85. set $rocket_bypass 0;
  86. set $rocket_reason “Arguments found”;
  87. }
  88.  
  89. # Do not bypass if the site is in maintenance mode
  90. if (-f “$document_root/.maintenance”) {
  91. set $rocket_bypass 0;
  92. set $rocket_reason “Maintenance mode”;
  93. }
  94.  
  95. # Do not bypass if one of those cookie if found
  96. # wordpress_logged_in_[hash] : When a user is logged in, this cookie is created (we’d rather let WP-Rocket handle that)
  97. # wp-postpass_[hash] : When a protected post requires a password, this cookie is created.
  98. if ($http_cookie ~* “(wordpress_logged_in_|wp\-postpass_|woocommerce_items_in_cart|woocommerce_cart_hash|wptouch_switch_toogle|comment_author_|comment_author_email_)”) {
  99. set $rocket_bypass 0;
  100. set $rocket_reason “Cookie”;
  101. }
  102.  
  103. if (-f “$rocket_mobile_detection”) {
  104. set $rocket_bypass 0;
  105. set $rocket_reason “Specific mobile cache activated”;
  106. }
  107.  
  108. # Do not bypass if the cached file does not exist
  109. if (!-f “$rocket_file”) {
  110. set $rocket_bypass 0;
  111. set $rocket_reason “File not cached”;
  112. }
  113.  
  114. # If the bypass token is still on, let’s bypass WordPress with the cached URL
  115. if ($rocket_bypass = 1) {
  116. set $rocket_is_bypassed “Yes”;
  117. set $rocket_reason “$rocket_url”;
  118. }
  119.  
  120. # Clear variables if debug is not needed
  121. if ($rocket_debug = 0) {
  122. set $rocket_reason “”;
  123. set $rocket_file “”;
  124. }
  125.  
  126. # If the bypass token is still on, rewrite according to the file linked to the request
  127. if ($rocket_bypass = 1) {
  128. rewrite .* “$rocket_url” last;
  129. }
  130.  
  131. # Add header to HTML cached files
  132. location ~ /wp-content/cache/wprocket/.*html$ {
  133. add_header Vary “Accept-Encoding, Cookie”;
  134. add_header XRocketNginxBypass $rocket_is_bypassed;
  135. add_header XRocketNginxReason $rocket_reason;
  136. add_header XRocketNginxFile $rocket_file;
  137. add_header StrictTransportSecurity “$rocket_hsts_value”;
  138. expires 30d;
  139. #!# HEADER_HTTP #!#
  140. #!# HEADER_NON_GZIP #!#
  141. }
  142.  
  143. # Do not gzip cached files that are already gzipped
  144. location ~ /wp-content/cache/wprocket/.*_gzip$ {
  145. gzip off;
  146. types {}
  147. default_type text/html;
  148. add_header ContentEncoding gzip;
  149. add_header Vary “Accept-Encoding, Cookie”;
  150. add_header XRocketNginxBypass $rocket_is_bypassed;
  151. add_header XRocketNginxReason $rocket_reason;
  152. add_header XRocketNginxFile $rocket_file;
  153. add_header StrictTransportSecurity “$rocket_hsts_value”;
  154. expires 30d;
  155. #!# HEADER_HTTP #!#
  156. #!# HEADER_GZIP #!#
  157. }
  158.  
  159. # Debug header (when file is not cached)
  160. add_header XRocketNginxBypass $rocket_is_bypassed;
  161. add_header XRocketNginxReason $rocket_reason;
  162. add_header XRocketNginxFile $rocket_file;
  163.  
  164. # No HSTS header added here. We suppose it’s correctly added in the site configuration
  165.  
  166.  
  167. ###################################################################################################
  168. # BROWSER CSS CACHE
  169. #
  170. location ~* \.css$ {
  171. gzip_vary on;
  172. expires 30d;
  173. #!# HEADER_CSS #!#
  174. }
  175.  
  176.  
  177. ###################################################################################################
  178. # BROWSER JS CACHE
  179. #
  180. location ~* \.js$ {
  181. gzip_vary on;
  182. expires 30d;
  183. #!# HEADER_JS #!#
  184. }
  185.  
  186.  
  187. ###################################################################################################
  188. # BROWSER MEDIA CACHE
  189. #
  190. location ~* \.(ico|gif|jpe?g|png|svg|eot|otf|woff|woff2|ttf|ogg)$ {
  191. expires 30d;
  192. #!# HEADER_MEDIAS #!#
  193. }

以上代码复制保存为 rocket.conf 文件上传到你的 nginx/conf 目录中,然后我们只要在我们的vhsot文件中引入即可。

  1. # BEGIN WP rocket
  2. include /usr/local/nginx/conf/rocket.conf;
  3. # END WP rocket

然后 Nginx restart 重启一下使文件生效。按照如上配置好之后,查看网站源码,源码最底部就会出现安装成功后的提示如下:

  1. <!– This website is like a Rocket, isn’t it ? Performance optimized by WP Rocket. Learn more: http://wp-rocket.me – Debug: cached@1458565320 –>

能看到此信息,就说明完事ok了。

最后放下载地址:wp-rocket

原创文章,转载请注明: 转载自网页阁吧

本文链接地址: WordPress 缓存插件 WP Rocket

转载请注明:网页阁吧 » WordPress 缓存插件 WP Rocket

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址