ngx_int_t
ngx_open_cached_file(ngx_open_file_cache_t *cache, ngx_str_t *name,
ngx_open_file_info_t *of, ngx_pool_t *pool)
{
time_t now;
uint32_t hash;
ngx_int_t rc;
ngx_file_info_t fi;
ngx_pool_cleanup_t *cln;
ngx_cached_open_file_t *file;
ngx_pool_cleanup_file_t *clnf;
ngx_open_file_cache_cleanup_t *ofcln;
of->fd = NGX_INVALID_FILE;
of->err = 0;
//配置open_log_file_cache off的话,cache为空
if (cache == NULL) {
......
//添加一个cleanup
cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t));
if (cln == NULL) {
return NGX_ERROR;
}
//打开日志文件,获得fd rc = ngx_open_and_stat_file(name, of, pool->log);
rc = ngx_open_and_stat_file(name, of, pool->log);
//打开日志文件成功
if (rc == NGX_OK && !of->is_dir) {
//添加cleanup回调,在销毁内存池的时候调用ngx_pool_cleanup_file,函数内采用了close关闭fd
cln->handler = ngx_pool_cleanup_file;
clnf = cln->data;
【Nginx的error_log和Access_log分析 nginx access log】clnf->fd = of->fd;
clnf->name = name->data;
clnf->log = pool->log;
}
return rc;
}
......
}
2)如果配置open_file_log_cache的话,支持四种参数:
max = N [ inactive = time ] [ min_uses = N ] [ valid = time ]
max 最大缓存文件描述符数量
inactive 在多少时间内不活动,就会被删除
min_uses 必须在 inactive时间内活动N次,才会被缓存
valid 检查inactive的时间 。
具体的缓存文件fd的来龙去脉值得用一篇文章来详细描述,在这里就暂且不说了,希望最近有时间整理出来 。
The End
推荐阅读
- 耐克的这种鞋标怎么验真假求教啊
- Nginx安装配置PageSpeed模块实现网站加速
- Nginx配置error_page nginx配置errorlog
- 解决nginx一直跳转登录页面 解决Nginx:
- 解决nginx+php-fpm无法上传文件问题
- 被称为小神童的是哪位特级大师
- 美的变频e1是什么故障 美的变频e1是什么故障视频
- iPhonex摄像头是索尼的吗 苹果x的摄像头是索尼哪一款
- 大树稀的一面是什么
- 古代玻璃指的是什么