编程技术分享平台

网站首页 > 技术教程 正文

nginx log记录请求响应时间(实时查看nginx日志)

xnh888 2024-09-28 03:08:06 技术教程 52 ℃ 0 评论

有时为了方便分析接口性能等,需要记录请求的时长,通过修改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 to respond

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表