阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nginx 499错误码

135次阅读
没有评论

共计 1414 个字符,预计需要花费 4 分钟才能阅读完成。

今天发现 nginx 有不少的 499 错误,大约占了将近 0.5%,而且是在新上线了一个含 upstream 的业务之后。

grep 一下 nginx 源码,定义在 ngx_request_t.h

 
/*
* HTTP does not define the code for the case when a client closed
* the connection while we are processing its request so we introduce
* own code to log such situation when a client has closed the connection
* before we even try to send the HTTP header to it
*/
#define NGX_HTTP_CLIENT_CLOSED_REQUEST 499
 

这下就很清楚了,这是 nginx 定义的一个状态码,用于表示这样的错误:服务器返回 http 头之前,客户端就提前关闭了 http 连接。

再 grep 下“NGX_HTTP_CLIENT_CLOSED_REQUEST”,发现目前这个状态值只在 ngx_upstream 中赋值。

upstream 在以下几种情况下会返回 499:

(1)upstream 在收到读写事件处理之前时,会检查连接是否可用:ngx_http_upstream_check_broken_connection,

if (c->error) {//connecttion 错误 
……
if (!u->cacheable) { //upstream 的 cacheable 为 false,这个值跟 http_cache 模块的设置有关。指示内容是否缓存。ngx_http_upstream_finalize_request(r, u, NGX_HTTP_CLIENT_CLOSED_REQUEST); } }

如上代码,当连接错误时会返回 499。

(2)server 处理请求未结束,而 client 提前关闭了连接,此时也会返回 499。

(3)在一个 upstream 出错,执行 next_upstream 时也会判断连接是否可用,不可用则返回 499。

总之,这个错误的比例升高可能表明服务器 upstream 处理过慢,导致用户提前关闭连接。而正常情况下有一个小比例是正常的。

Nginx 的详细介绍 :请点这里
Nginx 的下载地址 :请点这里

相关阅读

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计1414字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中