2013-02-02 54 views
1

nginx.conf文件內容如下:nginx的webpy的FastCGI緩存不能工作

http { 
include  mime.types; 
default_type application/octet-stream; 

# configure cache log 
log_format cache '$remote_addr - $host [$time_local] ' 
      '"$request" $status $upstream_cache_status $body_bytes_sent ' 
      '"$http_referer" "$http_user_agent"'; 

fastcgi_cache_path /data0/nginx-cache levels=1:2 
        keys_zone=nginx_fastcgi_cache:1m 
        inactive=1d; 

        fastcgi_temp_path /data0/nginx-cache/temp; 

server { 
    listen  8080; 
    server_name outofmemory.cn localhost; 

    access_log /data0/nginx-1.2.6/logs/cache.log cache; 

    #charset koi8-r; 


    fastcgi_cache_key "$scheme$request_method$host$request_uri"; 
    fastcgi_cache nginx_fastcgi_cache; 
    fastcgi_cache_min_uses 1; 
    fastcgi_ignore_headers Cache-Control Expires; 
    fastcgi_cache_use_stale error timeout invalid_header http_500; 
    #add_header X-Cache cached; 

    fastcgi_cache_valid 60m; 

    location/{ 
     root /www/outofmemory.cn; 
     fastcgi_param REQUEST_METHOD $request_method; 
     fastcgi_param QUERY_STRING $query_string; 
     fastcgi_param CONTENT_TYPE $content_type; 
     fastcgi_param CONTENT_LENGTH $content_length; 
     fastcgi_param REMOTE_PORT $remote_port; 
     fastcgi_param SERVER_ADDR $server_addr; 
     fastcgi_param SERVER_PORT $server_port; 
     fastcgi_param SERVER_NAME $server_name; 
     fastcgi_param SERVER_PROTOCOL $server_protocol; 
     fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 
     fastcgi_param PATH_INFO $fastcgi_script_name; 
     fastcgi_pass 127.0.0.1:9002; 

     fastcgi_cache_key "$scheme$request_method$host$request_uri"; 
     fastcgi_cache nginx_fastcgi_cache; 
     fastcgi_cache_valid 60m; 
    } 

    } 
} 

任何幫助,將不勝感激。

謝謝。

回答

3

我也有同樣的問題。正如yukaizhao在他的文章中提到的,需要在下面添加忽略expires頭文件,否則fastcgi_cache將不起作用。

fastcgi_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; 

謝謝yukaizhao!

+0

我不太瞭解這個設置,但它在停止工作一段時間後對我有效。這個怎麼用?該文檔說「禁止處理來自FastCGI服務器的某些響應頭字段」,這是否意味着它只是去掉這些頭或允許?我不明白。 – ncla