nginx:fastcgi_cache_path為空

nginx:fastcgi_cache_path為空

我想嘗試fastcgi_cache我的 nginx 1.5.8 設置,如圖所示這裡

在 nginxconf 的 http 部分中,我加入了:

fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:10m
max_size=1000m inactive=60m;

在伺服器部分:

    set $cache_uri $request_uri;

    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
        set $cache_uri 'null cache';
    }
    if ($query_string != "") {
        set $cache_uri 'null cache';
    }

    # Don't cache uris containing the following segments
    if ($request_uri ~*
"(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)")
{
        set $cache_uri 'null cache';
    }

    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~*
"comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
        set $cache_uri 'null cache';
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi.conf;
        fastcgi_pass unix:/var/run/php5-fpm.sock;


        ##
        # Fastcgi cache
        ##
        set $skip_cache 1;
                if ($cache_uri != "null cache") {
                    add_header X-Cache-Debug "$cache_uri $cookie_nocache
$arg_nocache$arg_comment $http_pragma $http_authorization";
            set $skip_cache 0;
        }
        fastcgi_cache_bypass $skip_cache;
                   fastcgi_cache_key
$scheme$host$request_uri$request_method;
            fastcgi_cache_valid any 8m;
                   fastcgi_cache_bypass $http_pragma;
                fastcgi_cache_use_stale updating error timeout
invalid_header http_500;

    }

chown編輯了/var/cache/nginxwww-data 使用者(和群組)並將chmod其添加到了 775.我重新啟動了 nginx,但該資料夾始終為空。正常嗎?如何測試是否fastcgi_cache有效?

答案1

您還需要fastcgi_cache microcache;在配置的某個時刻進行設定。預設值null禁用快取:http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache

為了檢查它,請查看X-Cache-Debug回應中是否存在標頭。如果沒有,則表示您對可快取的內容限製過多。 Nginx 也尊重Cache-Control您在 HTTP 回應中設定的標頭 - 您可以在應用程式中使用/檢查它,而不是添加太多的快取條件。

答案2

是的,這很正常。

您的配置中沒有任何地方有fastcgi_cache指示。

如果未指定,則隱含值為off。如果您想要繼續進行任何緩存,您最好fastcgi_cache microcache;在某處提及,其中該部分是您的frommicrocache的名稱。keys_zonefastcgi_cache_path

相關內容