nginx: fastcgi_cache_path が空です

nginx: fastcgi_cache_path が空です

fastcgi_cache私はnginx 1.5.8の設定で試してみたかったここ

nginx conf の 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;

    }

私はwww-data ユーザー (およびグループ) にchown変更し、それを に ded しました 。nginx を再起動しましたが、フォルダーは常に空です。これは正常ですか?が動作しているかどうかをテストするにはどうすればよいですか?/var/cache/nginxchmod775fastcgi_cache

答え1

fastcgi_cache microcache;設定のどこかの時点で設定する必要もあります。デフォルト値はnullキャッシュを無効にします。http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache

これを確認するには、X-Cache-Debugレスポンスにヘッダーがあるかどうかを確認します。ない場合は、キャッシュできる内容が制限されすぎています。Nginx は、Cache-ControlHTTP レスポンスに設定したヘッダーも尊重します。つまり、キャッシュの条件をあまり追加せずに、アプリケーションでヘッダーを使用/確認できます。

答え2

はい、正常です。

あなたの設定にはどこにもfastcgi_cache指令。

指定されていない場合は、暗黙の値は ですoff。キャッシュを継続したい場合は、の部分がfromの名前でfastcgi_cache microcache;ある をどこかに指定することをお勧めします。microcachekeys_zonefastcgi_cache_path

関連情報