WP Fastest Cache,最简单和最快速的WP缓存系统。
1、本身是免费的,后台直接搜索 WP Fastest Cache,安装即可。
2、配合WP Fastest Cache高级版:wp-fastest-cache-premium使用!
3、WP Fastest Cache配置Nginx,实现真正的静态化
下面的配置可以使你的WP Fastest Cache达到真正的完全静态,(甚至PHP进程挂掉,网站依旧能正常运行)
下方是伪静态规则:
location / { # 如果请求的文件已存在,直接返回 if (-f $request_filename) { break; } set $caches 1; #是否缓存 set $request_file $document_uri; #获取请求文件 set $cache_file ''; #缓存文件 #请求方式是POST的不拦截 if ($request_method = POST) { set $caches 0; } #包含GET请求参数的不拦截(访问量高可以注释掉) if ($query_string) { set $caches 0; } # 指定静态缓存文件的路径 if ($caches = 0) { set $request_file ''; } if ($request_file ~ ^(.+)$) { set $cache_file /wp-content/cache/all/$1/index.html; #你的WP Fastest Cache缓存目录 } # 命中缓存 if (-f $document_root$cache_file) { rewrite ^ $cache_file last; } # 无法命中缓存,转给WordPress来处理 if (!-e $request_filename) { rewrite . /index.php last; } }
接着看看,你的网站打开速度是不是快了好多好多。
下面这个是无注释版,可直接使用在宝塔面板上。
location / { if (-f $request_filename) { break; } set $caches 1; set $request_file $document_uri; set $cache_file ''; if ($request_method = POST) { set $caches 0; } if ($query_string) { set $caches 0; } if ($caches = 0) { set $request_file ''; } if ($request_file ~ ^(.+)$) { set $cache_file /wp-content/cache/all/$1/index.html; } if (-f $document_root$cache_file) { rewrite ^ $cache_file last; } if (!-e $request_filename) { rewrite . /index.php last; } } rewrite /wp-admin$ $scheme://$host$uri/ permanent;
如果想在header中检测是否生效了,就添加下面的代码:
location /wp-content/cache/all/ { #这一行是你的WP Fastest Cache缓存文件路径 add_header Cache HIT; #添加header头,表示命中了缓存 }
下面是我的配置: