nginx的access log按小时生成

1、在server或location段进行配置

    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})"){
      set $year $1;
      set $month $2;
      set $day $3;
      set $hour $4;
      set $minutes $5;
      set $seconds $6;
    }

  access_log /tmp/niffler-$year-$month-$day-$hour-$minutes-access.log main;

2、在nginx ingress-controller上的配置,编辑/etc/nginx/template/nginx.tmpl

    ## start server {{ $server.Hostname }}
    server {
        server_name {{ $server.Hostname }} {{ $server.Alias }};
        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})"){
             set $year $1;
             set $month $2;
             set $day $3;
             set $hour $4;
             set $minutes $5;
             set $seconds $6;}
        access_log /var/log/nginx/ingress-$year-$month-$day-$hour-access.log upstreaminfo;

 

posted @ 2019-12-23 10:33  诗码者  阅读(1051)  评论(0编辑  收藏  举报