【问题标题】:Nginx: upstream prematurely closed connection while reading response header from upstreamNginx:上游过早关闭连接,同时从上游读取响应头
【发布时间】:2020-08-24 07:44:27
【问题描述】:

我有一个可通过 nginx 反向代理访问的 express API。除了一个使用 bcrypt 的处理程序之外,一切都运行良好。

我的 api nginx 配置:

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name api.dev;

ssl_certificate /root/ssl/cert.crt;
ssl_certificate_key /root/ssl/cert.key;

access_log /root/nginx_logs/api_access.log;
error_log /root/nginx_logs/api_error.log;

location / {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $host;
    proxy_pass http://api:8880;

    # Big timeout to test
    proxy_connect_timeout 1200s;
    proxy_send_timeout 1200s;
    proxy_read_timeout 1200s;
}
}

我的快递员:

try {
    const hashedPassword = await bcrypt.hash(payload.password, 10);
    return handlerResult.ok({});
} catch (err) {
    console.error(err);
}

当我在任何其他路由上请求我的 api 时,它可以工作,但使用此处理程序 nginx 会收到此错误:

[error] 29#29: *27 upstream prematurely closed connection while reading response header from upstream

如果我评论const hashedPassword = await bcrypt.hash(payload.password, 10);,错误就会消失。

一开始我以为是超时错误,但如你所见,我在 nginx 中写了 overkill timeout。

感谢您的阅读,如果您有任何问题,请问我:)

PS:对不起我的英语不好

【问题讨论】:

    标签: node.js docker express nginx bcrypt


    【解决方案1】:

    我实际上是通过使用 bcryptjs 而不是 bcrypt 来修复的!

    【讨论】:

    • 搜索整个网络,你的问题让我找到了正确的方向!
    猜你喜欢
    • 2018-03-12
    • 2018-09-21
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 2014-04-02
    • 2015-08-08
    • 1970-01-01
    • 2016-07-29
    相关资源
    最近更新 更多