加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

angularjs – 在Node应用程序的NGINX 502坏网关中,Http请求超时

发布时间:2020-12-13 21:37:56 所属栏目:Nginx 来源:网络整理
导读:我一直在抓住这个超时问题并希望得到一些帮助.我有一个http请求可能需要2.5分钟才能返回响应.我在Angular中处理超时处理3分钟,NodeJS处理3分钟.我的nginx设置有200秒超时,我的Elastic Load Balancing连接超时设置为4分钟.但是,我一直在2分钟内看到502坏网关n

我一直在抓住这个超时问题并希望得到一些帮助.我有一个http请求可能需要2.5分钟才能返回响应.我在Angular中处理超时处理3分钟,NodeJS处理3分钟.我的nginx设置有200秒超时,我的Elastic Load Balancing连接超时设置为4分钟.但是,我一直在2分钟内看到502坏网关nginx 1.4.6(Ubuntu)错误.有没有我错过超时的部分?

我的nginx设置:

server {
    listen 80;
    server_name;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log debug;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Connection "";
        proxy_http_version 1.1;
        proxy_pass http://localhost:8060;
        proxy_redirect off;
        proxy_connect_timeout 200s;
        proxy_send_timeout 200s;
        proxy_read_timeout 200s;
        send_timeout 200s;
    }
    #Handle protected assets using 'internal' directive documented here: https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/
    location /protected {
        internal;
        expires -1;
    }
}

我的NodeJS设置正在使用connect-timeout

var timeout = require('connect-timeout');
app.use(timeout(300000));
最佳答案
我今天刚刚遇到这个问题,并且可能找到了答案 – 节点的http模块中有120秒的硬编码超时.我不得不在给定的请求处理程序中设置socket超时,如下所示:

yourHandler(req,res) {
  req.socket.setTimeout(3600e3); // 1 hour

  // ... do the real work

  res.json(...);
}

您也可以将此限制设置为0以禁用此超时.

https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback

最初在这里找到答案:https://forum.nginx.org/read.php?2,214239#msg-214239

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读