zoukankan      html  css  js  c++  java
  • nginx访问日志中的时间格式修改

    1.说明

    默认的时间格式是:[08/Mar/2013:09:30:58 +0800],由$time_local变量表示。

    我想要改成如下格式:2013-03-08 12:21:03

    2.需要修改的文件

    src/core/nginx_times.c

    src/http/modules/ngx_http_log_module.c

    首先修改ngx_http_log_module.c文件:

    { ngx_string("time_iso8601"), sizeof("1970-09-28T12:00:00+06:00") - 1,
    更改后
    { ngx_string("time_iso8601"), sizeof("1970-09-28 12:00:00") - 1, 

    然后修改nginx_times.c文件:

    [sizeof("1970-09-28T12:00:00+06:00")];
    更改后
    [sizeof("1970-09-28 12:00:00")]; 
    ngx_cached_http_log_iso8601.len = sizeof("1970-09-28T12:00:00+06:00") - 1;
    更改为
    ngx_cached_http_log_iso8601.len = sizeof("1970-09-28 12:00:00") - 1;
    (void) ngx_sprintf(p3, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",  
                        tm.ngx_tm_year, tm.ngx_tm_mon,  
                        tm.ngx_tm_mday, tm.ngx_tm_hour,  
                        tm.ngx_tm_min, tm.ngx_tm_sec,  
                        tp->gmtoff < 0 ? '-' : '+',  
                        ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60)); 
    更改为
    (void) ngx_sprintf(p3, "%4d-%02d-%02d %02d:%02d:%02d",  
                        tm.ngx_tm_year, tm.ngx_tm_mon,  
                        tm.ngx_tm_mday, tm.ngx_tm_hour,  
                        tm.ngx_tm_min, tm.ngx_tm_sec); 

    3.重新编译,并使用新的时间变量

    配置文件中的$time_local改为$time_iso8601即可。

  • 相关阅读:
    mysql5.7慢查询开启配置
    easyui的datagrid删除一条记录后更新出问题
    easyui跨iframe属性datagrid
    struts2笔记12-声明式异常
    struts2笔记11-OGNL
    struts2笔记10-值栈
    linux命令学习03-grep
    struts2笔记09-动态方法调用
    1、GIT简介
    玩转Python语言之4:奇技淫巧
  • 原文地址:https://www.cnblogs.com/t-road/p/6868683.html
Copyright © 2011-2022 走看看