log nginx 显示时间_nginx日志如何正确显示整个http请求的服务端处理时间?

$request_time和$upstream_response_time之间差别:

$request_time包含了用户数据接收时间,而真正程序的响应时间应该用$upstream_response_time

下面介绍下2者的差别:

1、request_time

官网描述:request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client 。

指的就是从接受用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间、程序响应时间、输出

响应数据时间。

2、upstream_response_time

官网描述:keeps times of responses obtained from upstream servers; times are kept in seconds with a milliseconds resolution. Several response times are separated by commas and colons like addresses in the $upstream_addr variable

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx代理WebSocket之后,你可以通过以下步骤来查看与服务端交互的日志: 1. 在Nginx的配置文件中,将WebSocket连接的日志级别设置为debug或info。例如: ``` http { ... log_format mylog '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$upstream_addr" "$upstream_response_time" $upstream_http_upgrade $upstream_http_connection'; ... server { ... location /websocket/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; access_log /var/log/nginx/access.log mylog; error_log /var/log/nginx/error.log debug; } ... } } ``` 2. 重启Nginx服务以使配置生效。 3. 打开Nginx的访问日志文件(例如/var/log/nginx/access.log),查找与WebSocket连接相关的日志记录。日志文件中的每个条目都应包含代理服务器和后端服务器之间的交互信息。 4. 如果需要查看更详细的日志信息,可以打开Nginx的错误日志文件(例如/var/log/nginx/error.log),其中应包含有关代理服务器和后端服务器之间的所有交互的详细信息。 5. 此外,你还可以在后端WebSocket服务器上启用日志记录,以便查看与客户端之间的WebSocket交互。要启用WebSocket服务器的日志记录,请查看WebSocket服务器的文档或配置文件。 通过以上步骤,你应该能够找到与服务端交互的所有日志信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值