nginx一般做代理服务器较多,大多数缓存都是proxy cache,偶尔有些架构是nginx+php组合的,其缓存就是另一种
fastcgi cache.
配置

http段:

fastcgi_cache_path /dev/shm/nginx_cache levels=2:2 keys_zone=cgi_one:10m inactive=2d max_size=10g;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie ;

server段

set $skip_cache 0;
if ($request_method = POST) {
        set $skip_cache 1;
}
if ($request_uri ~ ^/admin/) {
    set $skip_cache  1;
}


fastcgi_cache            cgi_one;
fastcgi_cache_methods    GET;
fastcgi_cache_key        "$scheme$request_method$host$request_uri";
fastcgi_cache_valid      200 302 1d;
fastcgi_cache_use_stale  error timeout invalid_header http_500;
add_header               X-Cache "$upstream_cache_status";
fastcgi_no_cache $skip_cache;
fastcgi_cache_bypass $skip_cache;
include   fastcgi_params;

转载请注明出处:https://www.isres.com/nginx/181.html

添加新评论