104 案例
查看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的连接是长连接,需要自己开启
bash
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_pass http://bigdata;
#下面的timeout跟自己的业务相关设置对应的timeout
proxy_connect_timeout 120; //加大120
proxy_send_timeout 120; //加大120
proxy_read_timeout 120; //加大120
proxy_http_version 1.1; //开启后端,长连接
proxy_set_header Connection ""; //开启后端,长连接
}
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_pass http://bigdata;
#下面的timeout跟自己的业务相关设置对应的timeout
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的
https://blog.csdn.net/zzhongcy/article/details/89090193