nginx log记录请求响应时间

有时为了方便分析接口性能等,需要记录请求的时长,通过修改nginx的日志格式可以做到,如

添加一个新的log_format

log_format timed_combined '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for" '

'$request_time $upstream_response_time';

然后引用这个新的日志格式

access_log /var/log/nginx/access.log timed_combined;

上面新增的参数是

request_time -This shows how long Nginx dealt with the request

upstream_response_time - Gives us the time it took our upstream server (in this case Apache/mod_wsgi) to respond

nginx log记录请求响应时间

相关推荐