有时 Node.js 服务器响应错误(高负载)

时间:2021-03-08 15:57:31

标签: node.js nginx cors nginx-reverse-proxy

nodejs 服务器在高负载时响应错误消息。

一些错误是: Http failure response for (api url):0 Unknown Errorcors 错误。在浏览器控制台上。

在 Android 方面,错误是 unexpected end of stream on Connection {api url:80, proxy=Direct hostaddress=apiurl/serverip:80 cipherSuite=none protocol=http/1.1

我们有 16 GB ram 4vCPUs aws 实例

nginx 反向代理在 4 个节点实例(通过 pm2 创建)、ip_hash(因为我们使用的是 socketio)之间进行负载平衡

浏览网页时,一些建议是“Its cors error”、“it server side error, contact the backend team

对于 cors 我们使用来自 npm 的 cors 包。 app.use(cors())。我正在寻找服务器端固定。我们正在使用快递。

因为网站和应用程序在运行时可以完美运行,并且在出现问题时我们会出现 cors 错误。这可能不是 cors 错误。在高负载期间,我们立即得到错误,而不是超时错误。

我们无法找出问题所在。有什么建议吗?

更新:由于投票正在进行中,我可能无法得到答案,但这里有一些错误,请注意应用程序和网站(angular)工作正常,但在选择时间出现这些错误,我希望超时或节点停止,但不是这些错误,所以认为有问题。

error on console - Angular

error on android

Update2:在查看 nginx 错误日志时,我们收到此错误。

2021/03/09 17:10:25 [alert] 1058#1058: *2946806 768 worker_connections are not enough while connecting to upstream, client: 120.xx.xxx.114, server: api.mydomain.com, request: "GET /Image-1611905660330.jpg HTTP/1.1", upstream: "http://127.0.0.1:8000/Image-1611905660330.jpg", host: "api.mydomain.com"

更新3:查找上面的错误,发现建议增加worker_connections,所以更新/etc/nginx/nginx.conf;。现在我们得到错误 *2908 socket() failed (24: Too many open files) while connecting to upstream,

更新 4:将 worker_rlimit_nofile 20000; 添加到 /etc/nginx/nginx.conf 似乎修复了更新 3 上的错误。

1 个答案:

答案 0 :(得分:0)

cors 错误是由浏览器发出的,而不是服务器。服务器只提供浏览器 cors 策略响应。是否作为错误处理由浏览器自行决定。

我不是 android 开发人员,但我认为您的某些问题是由 android 客户端而不是服务器的滥用请求造成的。

Android connect Node.js REST unexpeceed end of stream

java.io.IOException: unexpected end of stream on Connection in android

相关问题