给WordPress加Cachify+Memcache的缓存

将其他cache优化的插件禁用。然后找到cachify插件并启用。

插件的官方地址和doc在:https://cachify.pluginkollektiv.org/documentation/settings/

配置

去nginx修改配置文件 – 在最后的error_log之前插入 – 重启nginx

###### 启用Cachify开始
## GZIP
gzip_static on;
## CHARSET
charset utf-8;
location / {
 #try_files $uri $uri/ /index.php?$args;
   error_page 404 405 = @nocache;
    if ( $query_string ) {
        return 405;
    }
    if ( $request_method = POST ) {
        return 405;
    }

  #移动端不缓存
  if ( $http_user_agent ~ "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT-)|(SonyEricsson)|(NEC-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC-)|(SED-)|(EMOL-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)" )
    {    
       return 405;
    }
  #移动端不缓存
  
    if ( $request_uri ~ "/wp-" ) {
        return 405;
    }
    if ( $http_cookie ~ (wp-postpass|wordpress_logged_in|comment_author)_ ) {
        return 405;
    }
    default_type text/html;
    add_header X-Powered-By Cachify;
    set $memcached_key $host$uri;
    memcached_pass 127.0.0.1:11211;
    expires 1h;
}
location @nocache {
    try_files $uri $uri/ /index.php?$args;
}
######### 启用Cachify结束

Cachify开启之前和之后的GTmetrix.com比较

进阶

Leave a Reply