nginx在配置文件中实现日志按分钟切割

个人学习笔记,谢绝转载!!!

原文:https://www.cnblogs.com/wshenjin/p/12871191.html


线上某个接口需要按分钟切割日志:

      location /lua {
          default_type 'text/plain';
          content_by_lua 'ngx.say("hello, lua")';
          set $logdatedir "nodate";
          set $logfilename "lua_access";
          if ( $time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})" ) {
                 set $logdatedir "$1$2$3";
                 set $logfilename "lua_access_$1$2$3$4$5";
          }
          access_log /data/logs/datelogs/$logdatedir/$logfilename.log access;
      }

/data/logs/datelogs/$logdatedir 日期路径nginx不会自动创建,需要配置定时任务提前预创建。

posted @ 2020-05-11 19:13  wshenJin  阅读(...)  评论(...编辑  收藏