获取504 GATEWAY_TIMEOUT NodeJs

Ond*_*kar 12 amazon-web-services node.js express

504 GATEWAY_TIMEOUT在60秒的页面加载后得到http响应.

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

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

我的代码:

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

更新:

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

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

也没有帮助.

UPDATE2: 我也尝试过/bin/www像这样增加超时:

var server = http.createServer(app);
server.timeout=600000;
Run Code Online (Sandbox Code Playgroud)

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

Fer*_*rin 5

通常,当一个作业花费超过 30 秒或 40 秒时,我通常会通知正在执行的用户,然后创建一个处理数据库的进程,而不是向服务器发出正常请求,以避免用户等待请求,并且为了避免超时问题,您可以尝试这样做,例如当您将服务器设置为侦听指定端口时:

//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;
Run Code Online (Sandbox Code Playgroud)

  • 为试图提供帮助而竖起大拇指 (4认同)

小智 5

在您的.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
Run Code Online (Sandbox Code Playgroud)


小智 5

从您的Update3信息中,我认为您应该配置您的nginx配置文件,例如:

server {
    listen  80;
    server_name     *.*;
    location / {
            proxy_pass http://192.168.0.100:8001;
            proxy_connect_timeout 60s;
            proxy_read_timeout 5400s;
            proxy_send_timeout 5400s;
            proxy_set_header host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_redirect default;
    }
}
Run Code Online (Sandbox Code Playgroud)

proxy_read_timeout和proxy_send_timeout与您的问题有关。