nginx fastcgi_cache
参考
http://www.cnxct.com/several-reminder-in-nginx-fastcgi_cache-and-php-session_cache_limiter
http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache
fastcgi_cache_path /data/files/game/nginxCache/content levels=1:2 keys_zone=Hpp:250m inactive=1d max_size=1G; fastcgi_temp_path /data/files/game/nginxCache/temp; fastcgi_cache_key "$scheme$request_method$host$request_uri$is_args$args"; fastcgi_cache_use_stale error timeout invalid_header http_500; #nocache fastcgi_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
server{ set $skip_cache 0; #post访问不缓存 if ($request_method = POST) { set $skip_cache 1; } #动态查询不缓存 if ($query_string ~* "nonocache") { set $skip_cache 1; } #后台等特定页面不缓存(其他需求请自行添加即可) if ($request_uri ~* "users") { set $skip_cache 1; } if ($request_uri ~* "reply.php") { set $skip_cache 1; } #对登录后的结果缓存(hehe就是一个判断登录与否的Cookei名称) if ($http_cookie ~* "ECM_ID") { set $skip_cache 1; } fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; add_header X-Cache "$upstream_cache_status From $host"; add_header KCache "$scheme$request_method$host$request_uri$is_args$args"; fastcgi_cache Hpp; fastcgi_cache_valid 200 301 302 1d; }
fastcgi_cache的清除需要使用ngx_cache_purge这个模块.
ngx_cache_purge 是 nginx 的第三方那个模块,用于清除
FastCGI, proxy, SCGI and uWSGI 缓存
参考:
点击打开链接https://www.cnhzz.com/nginx_cache_purge/
点击打开链接http://54im.com/nginx/ngx_cache_purge.html
或者
自己写方法删除缓存目录下的文件
举例:
fastcgi_cache_path /www/php_cache levels=1:2 keys_zone=cache_php:30m inactive=1d max_size=10g;
1:2会生成16*256个字目录
root@vbstevena nginxCache # find . -type f ./content/8/2d/4573270729c3db4e26e68198e5a1c2d8 ./content/4/81/75a8c077cb22d087cf61c233a2184814 ./content/1/6e/a4a589e68d5352e716f4033d01c026e1
<?php function purgeCache() { $url = $this->post("url"); if (empty($url) || !Cola_Com_Validate::url($url)) { exit("请输入正确的URL。"); } $md5 = md5($url); $cacheFile = $this->_cacheRoot . "/" . substr($md5, -1) . "/" . substr($md5, -3, 2) . "/" . $md5; if (!file_exists($cacheFile)) { exit("缓存不存在。"); } if (@unlink($cacheFile)) { echo "清除缓存成功。"; } else { echo "清除缓存失败。"; } }
参考:点击打开链接http://www.lvtao.net/server/224.html#comment-1904
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。