nginx 解决 readv() failed (104: Connection reset by peer)

100人浏览   2025-04-06 01:44:48

查看nginx error错误,发现上传接口报以下错:

2019/10/10 19:58:25 [error] 299784#0: *5967188 readv() failed (104: Connection reset by peer) while reading upstream, client: 59.34.155.7, server: xxxxxxxx, request: "POST /stream/tracking/file HTTP/1.1", upstream: "http://xxxxxxxx/stream/tracking/file", host: "xxxxxxxx"

这种错误日志不多,第一感觉就是上传文件过大,传输时间过长,然后连接被中断。


当使用nginx作为反向代理时,为了支持长连接,需要做到两点:

从client到nginx的连接是长连接,对于客户端来说,nginx长连接是默认开启的。
从nginx到server的连接是长连接,需要自己开启

upstream bigdata {  
    server 10.0.20.xx:18018;  
    server 10.0.20.xx:18018;  
    server 10.0.20.xx:18018;  
    server 10.0.20.xx:18018;  
    keepalive 100;   //根据qps来调整  
}    
  
location ~ / {  
。。。。。。。。。省略。。。。。。。。。。。。。  
    proxy_connect_timeout      120;   //加大120  
    proxy_send_timeout         120;   //加大120  
    proxy_read_timeout         120;   //加大120  
    proxy_http_version 1.1;    //开启后端,长连接  
    proxy_set_header Connection "";  //开启后端,长连接  
}  

注意:keepalive指定的数值是Nginx每个worker连接后端的最大长连接数,而不是整个Nginx的.

相关推荐