Nginx中查看请求的耗时

要在Nginx中查看请求的耗时,可以使用ngx_http_log_module模块来记录日志。

首先,需要确保已经安装了Nginx并且配置文件正常运行。然后按照下面的步骤进行操作:

打开Nginx的配置文件(通常位于/etc/nginx/nginx.conf);
在http部分添加或修改如下指令:

http {
...
log_format timed '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time';
access_log /var/log/nginx/access.log timed;
...
}

重新加载Nginx配置文件,命令为 :

sudo nginx -s reload;

现在每次有请求到达服务器时,都会将相关信息写入 /var/log/nginx/access.log 文件中,包括请求耗时。
若想直接查看最近的请求耗时,可以使用以下命令:
shell

tail -f /var/log/nginx/access.log | grep "GET\|POST"

这样就能显示最近的 GET 或 POST 请求及其对应的耗时。

希望上述内容对您有所帮助!

posted @   Lafite-1820  阅读(1370)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
点击右上角即可分享
微信分享提示