产品详细信息

Typecho插件_Nginx fastcgi缓存

自动发货 库存(1)

¥ 0.20 ¥ 1.00

电子邮箱
购买数量
支付方式
商品详情

Typecho插件_Nginx fastcgi缓存

 

本插件需要 WEB 服务器为 Nginx 并且需要 ngx_cache_purge 模块支持

 

●插件特性

 

支持所有页面缓存

支持内容修改之后自动更新内容、分类、首页缓存

支持评论生效更新缓存

支持登录状态下不缓存

支持搜索等动态页面不缓存

 

●使用方法

需要修改nginx配置文件,添加

 

```nginx

#下面2行的中的wpcache路径请自行提前创建,否则可能会路径不存在而无法启动nginx,max_size请根据分区大小自行设置

fastcgi_cache_path /www/server/nginx/fastcgi_cache_dir levels=1:2 keys_zone=fcache:250m inactive=1d max_size=1G;

fastcgi_temp_path /www/server/nginx/fastcgi_cache_dir/temp;

fastcgi_cache_key "$scheme$request_method$host$request_uri";

fastcgi_cache_use_stale error timeout invalid_header http_500;

#忽略一切nocache申明,避免不缓存伪静态等

fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

#Ps:如果是多个站点,以上内容不要重复添加,否则会冲突,可以考虑将以上内容添加到nginx.conf里面,避免加了多次。

```

 

```nginx

server

{

 ***略***

 set $skip_cache 0;

 #post访问不缓存

 if ($request_method = POST) {

  set $skip_cache 1;

 }

 #动态查询不缓存

 if ($query_string != "") {

  set $skip_cache 1;

 }

 #pjax查询缓存

 if ($query_string ~ "_pjax=(.*)") {

  set $skip_cache 0;

 }

 #后台等特定页面不缓存(其他需求请自行添加即可)

 if ($request_uri ~* "/admin/|/action/|/search/|/feed/|baidu_sitemap.xml|sitemap.xml") {

  set $skip_cache 1;

 }

 #对登录的用户不展示缓存

 if ($http_cookie ~* "typecho_authCode") {

  set $skip_cache 1;

 }

 location ~ [^/]\.php(/|$)

 {

  try_files $uri =404;

  fastcgi_pass unix:/tmp/php-cgi-74.sock;

  fastcgi_index index.php;

  include fastcgi.conf;

  include pathinfo.conf;

  #新增的缓存规则

  fastcgi_cache_bypass $skip_cache;

  fastcgi_no_cache $skip_cache;

  add_header X-Cuojue-Cache "$upstream_cache_status From $host";

  fastcgi_cache fcache;

  fastcgi_cache_valid 200 1d;

 }

 

 location ~* /{后台设置的token}/_clean_cache(/.*) {

  fastcgi_cache_purge fcache "$scheme$request_method$host$1$is_args$args";

 }

 ***略***

}

```

以上的

```nginx

 location ~* /{后台设置的token}/_clean_cache(/.*) {

  fastcgi_cache_purge fcache "$scheme$request_method$host$1$is_args$args";

 }

```

需要和后台设置的token一致,例如后台设置`1150AE6A4F7938AE754D`则这里设置为

```nginx

 location ~* /1150AE6A4F7938AE754D/_clean_cache(/.*) {

  fastcgi_cache_purge fcache "$scheme$request_method$host$1$is_args$args";

 }

```

 

●缓存效果

1.替换新的配置,并且重载Nginx之后,访问前台页面,查看header,会多出一个 X-Cuojue-Cache 标志。

2.X-Cuojue-Cache 一般会有3个状态:MISS、HIT、BYPASS。