nginx修改php导出时间格式,nginx 修改 time_local 时间格式

因为系统统计需要,需要将默认的time_local格式 23/Aug/2010:17:26:44 +0800修改为datetime格式,参考网上的方法,发现也有不正确。自己稍作修改:

保险起见,使用time_iso8601变量

cd到源码目录:

vi src/http/modules/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,

2.    vi src/core/ngx_times.c

找到:

static u_char  cached_http_log_iso8601[NGX_TIME_SLOTS]

[sizeof("1970-09-28T12:00:00+06:00")];

修改为:

static u_char  cached_http_log_iso8601[NGX_TIME_SLOTS]

[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;

找到:

p3 = &cached_http_log_iso8601[slot][0];

(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 

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.     重新编译:

./configure --prefix=/usr/local/nginx  --user=web --group=web --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/opt/sourcecode/pcre-8.32 --add-module=./nginx-http-concat

make

不要make install

然后停止nginx,将新编译好的nginx复制到原目录下即可

cp /objs/nginx /usr/local/nginx/sbin/

4.    修改conf文件

log_format  main  '$remote_addr - $remote_user $time_local "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

修改为:

log_format  main  '$remote_addr - $remote_user $time_iso8601 "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

/usr/local/nginx/sbin/nginx -t

没有问题的话就可以启动了

看下log:192.168.0.143 - - [2014-11-12 10:36:26] "GET...

OK!

你可能感兴趣的:(nginx修改php导出时间格式,nginx 修改 time_local 时间格式)