获取504个GATEWAY_TIMEOUT NodeJ [英] Getting 504 GATEWAY_TIMEOUT NodeJs

查看:232
本文介绍了获取504个GATEWAY_TIMEOUT NodeJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面加载60秒后,我收到504 GATEWAY_TIMEOUT http响应.

I am getting 504 GATEWAY_TIMEOUT http response after 60s of page loading.

这不是正在加载的实际页面,而是正在执行的进程.我希望它花费的时间超过60秒,并且我尝试增加超时值,但这没有帮助.

It is not an actual page that is being loaded, than rather a process that is being executed. I am expecting it to take longer than 60s and I've tried to increase the timeout value, but it didn't help.

我正在使用快速框架进行路由,并且将作业托管在EB(AWS Elastic Beanstalk)上.由于增加了我可能在AWS控制台的EB和负载均衡器上可能找到的所有超时值,因此我认为它必须是将超时设置为60s的应用程序本身.但是,我可能错了.

I am using express framework for routing and I host the job on EB (AWS Elastic Beanstalk). Since I have increased all timeout values that I could possibly find on EB and Load Balancers in AWS console, I assume it must be the app itself that has timeout set to 60s. However, I might be wrong.

我的代码:

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

更新:

除此之外,我尝试了另一种方法.我将此代码添加到了app.js:

Besides this, I've tried a different approach. I added this code to the app.js:

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

也没有帮助.

UPDATE2: 我还尝试过像这样在/bin/www中增加超时时间:

UPDATE2: I have also tried increasing the timeout in /bin/www like this:

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

UPDATE3: 我注意到超时与nginx配置有关.正如我的日志所说:upstream timed out (110: Connection timed out) while reading response header 但是,我找不到在弹性beantalk上编辑nginx配置的方法.我做了一些研究,但是对我来说,这一切似乎都不是标准的,对于这样简单的事情来说,它太死板了.

UPDATE3: I have noticed that the timeout is related to the nginx configuration. As my logs say: upstream timed out (110: Connection timed out) while reading response header However, I can't figure out a way to edit nginx config on Elastic beanstalk. I did some research, but it all seems non standard to me and too rigid for such simple thing.

推荐答案

在.ebextensions配置文件中,添加以下代码:

In your .ebextensions config file, add the following code:

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

这篇关于获取504个GATEWAY_TIMEOUT NodeJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆