不间断的提示502 Bad Gateway是什么意思呢?
发布于 2 年前 作者 zhujunel 3705 次浏览 来自 问答

项目用node+express+ejs写的h5页面,所有的数据都是通过调取java第三方接口的数据,然后用ejs渲染,放到测试环境测试的时候不间断的服务挂掉、报错"502 Bad Gat eway"nginx错误,请问如何解决呢?是获取接口的数据的问题吗? 例如获取接口的代码: router.get(’/:id’,function(req,res,next){ const params = { id:req.params.id } request({ url: ${API}course/detail, method: req.method, json: true, headers: { “content-type”: “application/json”, }, qs: params }, function(error, response, body) { if (!error && response.statusCode == 200) { res.render(‘learn’,body) } }); })

7 回复

服务怎么起的,有没有用 pm2 之类的守护进程

@rrbe 还没有,打算弄个pm2,现在是不确定我这个请求接口的方式对不对,还有没有更优的

@zhujunel 具体问题可以看具体的nginx日志,有可能是你调的api执行时间过长,返回超时,第三方接口调用时间是不确定的

@zhujunel

有可能是域名解析不稳定,有可能是第三方不稳定。

nginx配置文件加个resolver试试。

@rrbe 加了pm2,自动重启了,错误代码是这样 at new StatusCodeError (/apps/srv/instance/nodejs/node_modules/request-promise-core/lib/errors.js:32:15) at Request.plumbing.callback (/apps/srv/instance/nodejs/node_modules/request-promise-core/lib/plumbing.js:104:33) at Request.RP$callback [as _callback] (/apps/srv/instance/nodejs/node_modules/request-promise-core/lib/plumbing.js:46:31) at Request.self.callback (/apps/srv/instance/nodejs/node_modules/request/request.js:186:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (/apps/srv/instance/nodejs/node_modules/request/request.js:1163:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at IncomingMessage. (/apps/srv/instance/nodejs/node_modules/request/request.js:1085:12) at IncomingMessage.g (events.js:292:16) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickDomainCallback (internal/process/next_tick.js:128:9)

@coordcn 加个pm2后,发邮件报了个这样的错误 at new StatusCodeError (/apps/srv/instance/nodejs/node_modules/request-promise-core/lib/errors.js:32:15) at Request.plumbing.callback (/apps/srv/instance/nodejs/node_modules/request-promise-core/lib/plumbing.js:104:33) at Request.RP$callback [as _callback] (/apps/srv/instance/nodejs/node_modules/request-promise-core/lib/plumbing.js:46:31) at Request.self.callback (/apps/srv/instance/nodejs/node_modules/request/request.js:186:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (/apps/srv/instance/nodejs/node_modules/request/request.js:1163:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at IncomingMessage. (/apps/srv/instance/nodejs/node_modules/request/request.js:1085:12) at IncomingMessage.g (events.js:292:16) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickDomainCallback (internal/process/next_tick.js:128:9)

@zhujunel 你这都是第三方 node 模块或者 node 本身报的错误啊,只提示 StatusCodeError 错误 stack 贴完啊,这点信息不够啊

回到顶部