nginx日志如下:
- request_time:单位ms,请求处理时间,指nginx从客户端接受第一个字节开始,到把请求结果数据全部发送给客户端,并写入ngnix日志后为止到全部处理时间。(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 。)
- up_resp_time/upstream_response_time:单位ms,指nginx从后端获取结果的处理时间,从nginx和后端建立连接开始,到关闭连接为止,连接的后端地址为upstream_addr值。(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)
- up_addr/upstream_addr:后端服务地址。
- request_time时间肯定是要比up_resp_time要大的。
查看Nginx源码
Nginx源码分析:
- 当客户端主动关闭链接时,http状态代码中没有可以表示该状态的,但在nginx又需要记录,所以自定义了一个499这个状态来表示。
/*
* HTTP does notdefine the code for the case when a client closed
* the connectionwhile we are processing its request so we introduce
* own code to logsuch situation when a client has closed the connection
* before we even tryto send the HTTP header to it
*
*/
#define NGX_HTTP_CLIENT_CLOSED_REQUEST 499
配置项
proxy_ignore_client_abort:表示忽略客户端终止情况
默认为off关闭状态,当客户端网络中断请求时,nginx 服务器中断其对后端服务器的请求,并立即记录 499 日志。
设置为 on 开启,则nginx会忽略客户端中断,并一直等着代理服务执行返回,记录后端返回的请求的状态。
proxy_ignore_client_abort no;
注意:开启后nginx只会在读取超时时关闭连接,默认为60s,可能出现请求连接挤压的情况,所以默认情况下是关闭。
如果开启必须设置好proxy_read_timeout超时时间,并且nginx最好别做反向代理以外的事情。