使用 Cachify 插件把 WordPress 頁面緩存到 Memcached 中,讓網(wǎng)頁瞬間打開

發(fā)布于:
更新時間:2025-04-23

本文介紹了如何使用Cachify插件將WordPress頁面緩存到Memcached中,從而顯著提升網(wǎng)頁加載速度。通過將靜態(tài)內(nèi)容存儲在內(nèi)存中,減少數(shù)據(jù)庫查詢,Cachify能夠?qū)崿F(xiàn)頁面瞬間打開的效果。文章還詳細說明了插件的特性、配置方法以及配合Nginx使用的具體步驟,幫助用戶輕松優(yōu)化WordPress性能。

我們提供 WordPress主題和插件定制開發(fā)服務(wù)

本站長期承接 WordPress主題、插件、基于 WooCommerce 的商店商城開發(fā)業(yè)務(wù)。 我們有 10 年WordPress開發(fā)經(jīng)驗,如果你想 用WordPress開發(fā)網(wǎng)站, 請聯(lián)系微信: iwillhappy1314,或郵箱: [email protected] 咨詢。

13 thoughts on “使用 Cachify 插件把 WordPress 頁面緩存到 Memcached 中,讓網(wǎng)頁瞬間打開

  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 here in /www/server/nginx/conf/nginx.conf:13
    nginx: configuration file /www/server/nginx/conf/nginx.conf test failed

  3. 狠狠心,把站點搬到HK AliYun,花時間配置了博主提到的緩存插件,同時關(guān)閉了騰訊云的海外CDN加速。如今,終于可以體驗到什么叫秒開WordPress了。

    ¥24/月的WordPress,終于能秒開了,差點喜極而泣。

  4. 提示錯誤:nginx: [emerg] “l(fā)ocation” directive is not allowed here in /www/server/nginx/conf/nginx.conf:13
    那是因為添加的配置放錯了位置,應(yīng)該放在標題為server的中括號里面

    1. 這個要根據(jù)你的 Nginx 配置來調(diào)整,文章中的代碼只是示例,在我的虛擬主機中配置中是正常的。

  5. 十分謝謝這篇文章,我是裝了最新寶塔,安裝了Memcached和opcache,在 Nginx配置文件里添加代碼時也跟其他人一樣報錯,我就只裝了Cachify試了以下,發(fā)現(xiàn)也是奏效的,所以想問一下Nginx那段配置代碼不使用的話,會引發(fā)什么問題嗎?

    1. 還是我,配置文件加代碼加在末尾就報錯,調(diào)整了位置放在server里就不報錯了,再次謝謝。

    2. 不添加 Nginx 配置的話,只能用緩存到數(shù)據(jù)庫的方式,效率沒有 memcached 或 hdd 方式高。

  6. 請問下,我在寶塔面板里面安裝了Memcached,但是插件里面的緩存方式,只有:數(shù)據(jù)庫 和 硬盤?
    這個是怎么回事呢?

發(fā)表回復(fù)

您的郵箱地址不會被公開。 必填項已用 * 標注

*