Nginx状态码499原因分析和处理

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最好别做反向代理以外的事情。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lizz666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值