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편집 하고 . 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. 캐싱을 계속하려면 fastcgi_cache microcache;어딘가에 해당 부분 microcache의 이름을 언급하는 것이 좋습니다 .keys_zonefastcgi_cache_path

관련 정보