nginx 请求时间详解
nginx 请求时间详解

nginx 请求时间详解

文章目录[隐藏]

背景

用户反馈广告主平台上传视频满,在本地尝试重现,发现上传一个30M左右的视频大概花40s左右,多个视频上传还是串行,目前前端已经优化为了并行上传,但一个视频花费40s的问题还是需要解决,因此就想把每个步骤操作时间都记录一下排查问题

流程

浏览器 –> nginx –> server –> 3rd server
nginx 请求时间详解插图

疑问

想在nginx日志配置中找到记录请求开始时间的变量,发现没有,一顿查阅得到的信息大致如下:

具体解释如下:

意思就是这个$time_local 是很接近请求处理结束时间


那么怎么去拿到request start time呢? 有这样的方式,如下:
$msec – $request_time ===   该条请求写日志时间戳 减去 请求处理时间 ,即请求开始时间


具体log format的变量解释官方解释如下:

中文版本:


  

参考资料

http://www.ttlsa.com/linux/the-nginx-log-configuration/
http://nginx.org/en/docs/http/ngx_http_log_module.html
https://www.nginx.com/blog/using-nginx-logging-for-application-performance-monitoring/#var_upstream_response_time
https://nginx.org/en/docs/http/ngx_http_upstream_module.html?&_ga=2.132295757.2109258733.1589278738-1303059860.1589278738#var_upstream_response_time
https://serverfault.com/questions/532560/how-to-log-the-start-time-of-a-request-in-nginx/859293

Visits: 24

发表回复