【问题标题】:Nginx proxy + Node: upstream prematurely closed connection while reading response header from upstreamNginx代理+节点:上游过早关闭连接,同时从上游读取响应头
【发布时间】:2019-09-13 08:36:59
【问题描述】:

我有一个具有三个端点的 Node 应用程序。

在前面,我有一个 Nginx 代理来平衡对 5 个应用程序实例的请求。

Nginx 设置为将三个不同的域代理到三个端点中的每一个。

我在 Nginx 上丢弃了很多错误请求:

upstream prematurely closed connection while reading response header from upstream

upstream server temporarily disabled while reading response header from upstream

我正在使用 PM2 运行 Node 应用程序。所有错误日志都是空的,我可以从正常运行时间中看到应用程序没有重新启动或失败。

这是我的 Nginx 配置:

upstream nodes {
    server xx.xx.xx.xx:3000;
    ... 5 instances
}

server {
    listen 443 ssl;
    server_name api.service1.io;

    location / {
            proxy_pass http://nodes/service1;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }

    ... ssl config
}

server {
    listen 443 ssl;
    server_name api.service2.io;

    location / {
            proxy_pass http://nodes/service2;
            ... same as above
    }
}

server {
    listen 443 ssl;
    server_name api.service3.io;

    location / {
            proxy_pass http://nodes/service3;
            ... same as above
    }
}

服务每天运行大约 100 万个请求,但应用服务器根本没有推送。

【问题讨论】:

    标签: node.js express nginx pm2


    【解决方案1】:

    尝试使用:

        proxy_connect_timeout   60; #suite your need
        proxy_read_timeout      600; #suite your need
        proxy_send_timeout      600; #suite your need
    

    可能和超时有关...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-12
      • 2017-08-12
      • 2018-09-21
      • 2018-06-11
      • 2020-03-19
      • 1970-01-01
      • 2014-04-02
      • 2015-08-08
      相关资源
      最近更新 更多