简体   繁体   English

413 请求实体太大 - Elastic Beanstalk + 负载均衡器 + Node.js 应用程序

[英]413 Request Entity Too Large - Elastic Beanstalk + Load Balancer + Node.js application

I have looked on all possible stackoverflow posts and have tried all the different aproaches.我查看了所有可能的 stackoverflow 帖子并尝试了所有不同的方法。 None worked.没有工作。 There seems also no official documentation on this.似乎也没有关于此的官方文档。 Everything works fine in my local app, and I can upload images of any size, but as soon as its deployed in my elastic beanstalk, I seem to have a limit of 1M per image upoad.在我的本地应用程序中一切正常,我可以上传任何大小的图像,但是一旦它部署在我的弹性 beanstalk 中,我似乎每个图像 upoad 的限制为 1M。

The Problem: Every time a user posts an image that is larger than 1MB, I receive the 413 error message with nginx.问题:每次用户发布大于 1MB 的图像时,我都会收到 413 错误消息 nginx。

Elastic Beanstalk Log: 2020/07/28 17:22:53 [error] 10404#0: *62 client intended to send too large body: 2800500 bytes, client: 172.31.18.162, server: , request: "POST /comment/image_post/11003031 HTTP/1.1", host: "myapp.com", referrer: "https://myapp.com/11003031" Elastic Beanstalk 日志:2020/07/28 17:22:53 [错误] 10404#0: *62 客户端打算发送太大的正文:2800500 字节,客户端:172.31.18.162,服务器:,请求:“POST /comment/ image_post/11003031 HTTP/1.1", host: "myapp.com", referrer: "https://myapp.com/11003031"

What I did to try to solve the problem:我为解决问题所做的工作:

I created a.ebextensions folder in my node.js application root folder, added the below code and called it proxi.config, and pushed it to my github which deploys to Elastic Beanstalk via pipeline.我在我的 node.js 应用程序根文件夹中创建了一个 .ebextensions 文件夹,添加了以下代码并将其命名为 proxi.config,并将其推送到我的 github,它通过管道部署到 Elastic Beanstalk。 I can see the proxi.config in my repository but for some reason it is automatically overwritten by the load balancer (I guess from what I have been reading).我可以在我的存储库中看到 proxi.config,但由于某种原因,它会自动被负载均衡器覆盖(我猜是根据我一直在阅读的内容)。

    proxi.config
container_commands:
  01_reload_nginx:
    command: "service nginx reload"
files:
    "/etc/nginx/conf.d/proxy.conf":
      mode: "000755"
      owner: root
      group: root
      content: |
        client_max_body_size 25M;

If this is complicated to solve, is there no other way to increase the 1M limit?如果这个解决起来比较复杂,有没有办法提高1M的限制?

The probable reason why your proxy.conf is not being used is because you are using current version of EB, which runs on Amazon Linux 2 (AL2).您的proxy.conf未被使用的可能原因是因为您使用的是当前版本的 EB,它在Amazon Linux 2 (AL2) 上运行。 However, the proxy settings you are trying to use are for old version of EB running on AL1.但是,您尝试使用的代理设置适用于在 AL1 上运行的旧版 EB。

For AL2, the nginx settings should be placed in .platform folder, not in .ebextenations as shown in the docs .对于 AL2,nginx 设置应放在.platform文件夹中,而不是如文档中所示的.ebextenations中。

Thus you can try the following:因此,您可以尝试以下操作:

File .platform/nginx/conf.d/myconfig.conf with the content of文件.platform/nginx/conf.d/myconfig.conf的内容

client_max_body_size 25M;

Please note that I can't verify the nginx setting it self.请注意,我无法自行验证 nginx 设置。 It still may not work as it may be wrong setting or have wrong form.它仍然可能无法工作,因为它可能设置错误或格式错误。 But the use of .ebextenations instead of .platform is definitely an issue on AL2 EB environments.但是使用.ebextenations而不是.platform绝对是 AL2 EB 环境中的一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的示例应用程序 Elastic Beanstalk + Node.js 总是失败? - Why is my sample application Elastic Beanstalk + Node.js keep failing? AWS Elastic Beanstalk 负载均衡器未显示 SSL 证书 - AWS Elastic Beanstalk load balancer not showing SSL certificate 为什么当尝试上传大视频时,App Engine gcloud 会抛出错误 413 entity too large? - why when try upload a large video, app engine gcloud throws error 413 entity too large? 如何在没有负载均衡器的情况下为 HTTPS 在 Elastic Beanstalk 上配置 Springboot 后端服务器 - How to configure Springboot backend server on Elastic Beanstalk for HTTPS without load balancer 在一个应用程序 Elastic Beanstalk 中测试和生产版本? - Test and Prod Version in One Application Elastic Beanstalk? 使用 terraform 从弹性 beantalk 应用程序设置弹性负载平衡的密码 - Setting the cipher for an elastic load balance from an elastic beanstalk app with terraform Elastic Beanstalk 在启动实例后过早检查运行状况 - Elastic Beanstalk checking health too soon after launching instance 应用程序负载均衡器 https 请求到在端口 3000 上运行的 EC2 nodejs - Application Load Balancer https request to EC2 nodejs running on port 3000 尝试在 Node.js 中加载所有 firestore 文档 - Trying to load all firestore documents in Node.js 使用端口配置应用程序负载均衡器 - Configuring Application Load Balancer with ports
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM