关于nginx日志中的time_local

查看:903
本文介绍了关于nginx日志中的time_local的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

想基于nginx日志统计某一接口如秒杀的最大并发数 nginx日志格式是这样配置的

log_format: $remote_addr [$time_local] "$request" $status $upstream_response_time $body_bytes_sent

Nginx官方文档是这样定义time_local

$time_local

local time in the Common Log Format

现在不确定这是请求过来的时间 还是请求处理完毕后记录此条日志的时间 只有是前者才能基于该时间统计最大并发数吧

解决方案

摘自:http://serverfault.com/questi...

The $local_time variable contains the time when the log entry is written.

when the HTTP request header is read, nginx does a lookup of the associated virtual server configuration. If the virtual server is found, the request goes through six phases:

  • server rewrite phase

  • location phase

  • location rewrite phase (which can bring the request back to the previous phase)

  • access control phase

  • try_files phase

  • log phase

Since the log phase is the last one, $local_time variable is much more colse to the end of the request than it's start.

这篇关于关于nginx日志中的time_local的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆