nginx日志缓存open_log_file_cache 太过爱你忘了你带给我的痛 2022-12-28 06:27 92阅读 0赞 ## nginx日志缓存,提升磁盘性能 ## > 将多个日志进行积累,达到一定量级后写入到磁盘,可以减少磁盘旋转,从而降低磁盘i/o,提升nginx能效 语法: access_log path access_log [存储路径] [buff=大小] [gzip=压缩级别] [flush=time 刷新时间] max: 最大字节数量。 inactive:设置时间 默认是10s min_uses:日志写入指定次数后压缩 valid:设置检查频率,默认60s off:禁用缓存 1. 全局定义 log_format 日志格式 log_format aaa '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" "$http_user_agent"'; 2. http server配置 access_log /application/nginx/logs/access_81.log aaa buffer=64k flush=1m; open_log_file_cache max=1000 inactive=20s valid=1m min_uses=1s; ##解释: buffer=64k #日志文件缓存在内存中的大小 flush=1m #内存中日志存留一分钟 max=1000 #文件描述符 inactive=20s #日志文件在缓存中没有被使用就会被取消 valid=1m #默认 1m 或 60s 两个单位都可以使用 min_uses=1 #在存活时间内日志被写入几次才会记录到缓存 3. 重启nginx 官方文档: [http://nginx.org/en/docs/http/ngx\_http\_log\_module.html\#open\_log\_file\_cache][http_nginx.org_en_docs_http_ngx_http_log_module.html_open_log_file_cache] [http_nginx.org_en_docs_http_ngx_http_log_module.html_open_log_file_cache]: http://nginx.org/en/docs/http/ngx_http_log_module.html#open_log_file_cache
还没有评论,来说两句吧...