获取504 GATEWAY_TIMEOUT NodeJs

在页面加载60s后,我得到了504 GATEWAY_TIMEOUT http响应。

这不是一个正在加载的实际页面,而是一个正在执行的进程。 我期待它花费超过60秒,我试图增加超时值,但它没有帮助。

我使用快速框架进行路由,并在EB(AWS Elastic Beanstalk)上托pipe作业。 由于我已经增加了在AWS控制台中的EB和负载平衡器上可能find的所有超时值,因此我认为它必须是超时设置为60秒的应用程序本身。 不过,我可能是错的。

我的代码:

 /* GET home page. */ router.get('/main',function(req, res, next) { req.connection.setTimeout(600000); mainProcess(res); //res.send("mainProcess() called"); }); 

更新:

除此之外,我尝试了不同的方法。 我将这段代码添加到app.js

 var connectTimeout = require('connect-timeout'); var longTimeout = connectTimeout({ time: 600000 }); app.use(longTimeout); 

也没有帮助。

UPDATE2:我也尝试增加/bin/www的超时时间,如下所示:

 var server = http.createServer(app); server.timeout=600000; 

UPDATE3:我已经注意到超时与nginxconfiguration有关。 正如我的日志说: upstream timed out (110: Connection timed out) while reading response header然而,我不能找出一种方式来编辑Elastic beanstalk上的nginxconfiguration。 我做了一些研究,但是对于我来说这一切似乎都不是标准的,对于这样简单的事情来说太僵化。

通常情况下,当一项工作超过30秒或40秒时,我通常会通知正在执行的用户,然后创build一个与数据库一起工作的进程,而不是对服务器的正常请求,以避免用户等待请求为了避免这个超时问题,你可以尝试这个例如当你设置服务器侦听指定的端口:

 //Create server with specified port var server = app.listen(app.get('port'), function() { debug('Express server listening on port ' + server.address().port); }); //set timeout time server.timeout = 1000; 

在.ebextensions中添加下面的代码:

  container_commands: change_proxy_timeout: command: | sed -i '/\s*location \/ {/c \ location / { \ proxy_connect_timeout 300;\ proxy_send_timeout 300;\ proxy_read_timeout 300;\ send_timeout 300;\ ' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf