nginx 错误日志分析

一、Nginx配置和内核优化 实现突破十万并发

二、一次Nignx的502页面的错误记录

(1)错误页面显示

 

错误日志:

2017/07/17 17:32:57 [error] 29071#0: *96 recv() failed (104: Connection reset by peer) while reading response header from upstream,
 client: 101.226.125.118, server: live.baidu.com, request: "GET /live/CY00013 HTTP/1.1", upstream: "http://show.baidu.com/live/123.html", host: "live.baidu.com"

(2)配置以及流程设置

本次采用Openresty 搭建的web服务器,使用代理服务器IP(192.168.1.166)代理被代理服务器IP(172.16.0.166)。改配置以及流程一直是合适的,结果在今天下午访问代理服务器出现Nginx 502 错误。配置信息:

复制代码

    server {
        listen       80;
        #resolver 8.8.8.8;
        server_name   live.baidu.com;

        location / {
                proxy_pass http://show.baidu.com;
                proxy_set_header Host show.baidu.com;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Real-PORT $remote_port;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

复制代码

IP地址和域名对应关系:

show.baidu.com (172.16.0.166)
live.baidu.com (192.168.1.166)

经过各种百度和google都说是后端服务器的原因,但是访问后端服务器也是正常的show.baidu.com (172.16.0.166),但是当访问关于一个和Redis有关的页面的时候就会出现,redis服务器已经断开连接,重启Redis服务器后正常工作

(3)总结:如果当前服务器是代理服务器,出现502的错误原因,则一般都是后端服务器的异常导致的

三、nginx错误日志文件Error.log常见错误详细说明

我们经常遇到各种各样的nginx错误日志,平时根据一些nginx错误日志就可以分析出原因了。不过不是很系统,这里网上看到一篇资料还是比较系统的关于nginx的error.log的详细说明,这里记录下,方便以后查看了解。

 

以上表格来自网络资料。这里只是记录下,方便以后查看。

四、Nginx错误日志说明

错误日志类型

  • 类型1: upstream timed out

  • 类型2: connect() failed

  • 类型3: no live upstreams

  • 类型4: upstream prematurely closed connection

  • 类型5: 104: Connection reset by peer

  • 类型6: client intended to send too large body

  • 类型7: upstream sent no valid HTTP/1.0 header

 

类型

错误日志

原因

解决办法

1upstream timed out (110: Connection timed out) while connecting to upstreamnginx与upstream建立tcp连接超时,nginx默认连接建立超时为200ms排查upstream是否能正常建立tcp连接
1upstream timed out (110: Connection timed out) while reading response header from upstreamnginx从upstream读取响应时超时,nginx默认的读超时为20s,读超时不是整体读的时间超时,而是指两次读操作之间的超时,整体读耗时有可能超过20s排查upstream响应请求为什么过于缓慢
2connect() failed (104: Connection reset by peer) while connecting to upstreamnginx与upstream建立tcp连接时被reset排查upstream是否能正常建立tcp连接
2connect() failed (111: Connection refused) while connecting to upstreamnginx与upstream建立tcp连接时被拒排查upstream是否能正常建立tcp连接
3no live upstreams while connecting to upstreamnginx向upstream转发请求时发现upstream状态全都为down排查nginx的upstream的健康检查为什么失败
4upstream prematurely closed connectionnginx在与upstream建立完tcp连接之后,试图发送请求或者读取响应时,连接被upstream强制关闭排查upstream程序是否异常,是否能正常处理http请求
5recv() failed (104: Connection reset by peer) while reading response header from upstreamnginx从upstream读取响应时连接被对方reset排查upstream应用已经tcp连接状态是否异常
6client intended to send too large body客户端试图发送过大的请求body,nginx默认最大允许的大小为1m,超过此大小,客户端会受到http 413错误码
  1. 调整请求客户端的请求body大小;

  2. 调大相关域名的nginx配置:client_max_body_size;

7upstream sent no valid HTTP/1.0 headernginx不能正常解析从upstream返回来的请求行 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值