关于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

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

阅读 13.5k
1 个回答

摘自: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.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题