使用 Cachify 插件把 WordPress 页面缓存到 Memcached 中,让网页瞬间打开

发布于:
更新时间:2022-01-12

我们提供 WordPress主题和插件定制开发服务

本站长期承接 WordPress主题、插件、基于 WooCommerce 的商店商城开发业务。 我们有 10 年WordPress开发经验,如果你想 用WordPress开发网站, 请联系微信: iwillhappy1314,或邮箱: amos@wpcio.com 咨询。

13 thoughts on “使用 Cachify 插件把 WordPress 页面缓存到 Memcached 中,让网页瞬间打开

  1. location / {
        error_page 404 405 = @nocache;
     
        if ( $query_string ) {
            return 405;
        }
        if ( $request_method = POST ) {
            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 localhost:11211;
    }
    
    location @nocache {
        try_files $uri $uri/ /index.php?$args;
    }

    这个在宝塔面板里的站点,保存出错???

    1. 官方文档

      ## GZIP
      gzip_static on;
      
      ## CHARSET
      charset utf-8;
      
      ## INDEX LOCATION
      location / {
      	error_page 404 405 = @nocache;
       
      	if ( $query_string ) {
      		return 405;
      	}
      	if ( $request_method = POST ) {
      		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 localhost:11211;
      }
      
      ## NOCACHE LOCATION
      location @nocache {
      	try_files $uri $uri/ /index.php?$args;
      }
  2. nginx: [emerg] “location” directive is not allowed
    在宝塔设置出错呢

  3. 提示错误:nginx: [emerg] “location” directive is not allowed here in /www/server/nginx/conf/nginx.conf:13
    nginx: configuration file /www/server/nginx/conf/nginx.conf test failed

  4. 狠狠心,把站点搬到HK AliYun,花时间配置了博主提到的缓存插件,同时关闭了腾讯云的海外CDN加速。如今,终于可以体验到什么叫秒开WordPress了。

    ¥24/月的WordPress,终于能秒开了,差点喜极而泣。

  5. 提示错误:nginx: [emerg] “location” directive is not allowed here in /www/server/nginx/conf/nginx.conf:13
    那是因为添加的配置放错了位置,应该放在标题为server的中括号里面

    1. 这个要根据你的 Nginx 配置来调整,文章中的代码只是示例,在我的虚拟主机中配置中是正常的。

  6. 十分谢谢这篇文章,我是装了最新宝塔,安装了Memcached和opcache,在 Nginx配置文件里添加代码时也跟其他人一样报错,我就只装了Cachify试了以下,发现也是奏效的,所以想问一下Nginx那段配置代码不使用的话,会引发什么问题吗?

    1. 还是我,配置文件加代码加在末尾就报错,调整了位置放在server里就不报错了,再次谢谢。

    2. 不添加 Nginx 配置的话,只能用缓存到数据库的方式,效率没有 memcached 或 hdd 方式高。

  7. 请问下,我在宝塔面板里面安装了Memcached,但是插件里面的缓存方式,只有:数据库 和 硬盘?
    这个是怎么回事呢?

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

*