【问题标题】:AWS showing it's own error screen even when the error handler exists in Expressjs即使 Expressjs 中存在错误处理程序,AWS 也会显示它自己的错误屏幕
【发布时间】:2021-10-05 19:23:41
【问题描述】:
app.use((err, req, res, next) => {
    if (err.type === 'entity.too.large')
        res.send(
            '<p align="center">Please upload an image below the defined limit of 5 MB. <br> Click <a href="/create">here</a> to visit the upload page again.</p>'
        )
    else res.redirect('/')
})

我有这段代码来捕捉错误。但是 AWS 仍然显示这个而不是预期的文本。

应用托管在 Elastic Beanstalk 的 EC2 实例中。

【问题讨论】:

    标签: node.js express amazon-elastic-beanstalk


    【解决方案1】:

    使用以下文件夹结构创建proxy.conf 文件。 根目录应该有 .platform 文件夹。

    .platform\nginx\conf.d\proxy.conf
    

    并在根文件夹中粘贴此代码。

    client_max_body_size 50M;
    large_client_header_buffers 4 32k;
    fastcgi_buffers 16 32k;
    fastcgi_buffer_size 32k;
    proxy_buffer_size   128k;
    proxy_buffers   4 256k;
    proxy_busy_buffers_size   256k;
    

    【讨论】:

    • 您的意思是将代码粘贴到proxy.config文件中吗?
    • @AnshAgarwal 是的。
    猜你喜欢
    • 2012-04-09
    • 2016-12-15
    • 2019-12-14
    • 2023-03-20
    • 1970-01-01
    • 2022-12-12
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多