简体   繁体   English

在 Elastic Beanstalk 节点上配置 nginx client_max_body_size

[英]Configuring nginx client_max_body_size on Elastic Beanstalk Node

I have a Node 10 app running on Elastic Beanstalk, and it throws 413 errors when the request payload is larger than ~1MB.我有一个在 Elastic Beanstalk 上运行的 Node 10 应用程序,当请求有效负载大于 ~1MB 时,它会引发 413 错误。

<html>

<head>
    <title>413 Request Entity Too Large</title>
</head>

<body>
    <center>
        <h1>413 Request Entity Too Large</h1>
    </center>
    <hr>
    <center>nginx/1.16.1</center>
</body>

</html>

The request is not hitting my app at all;该请求根本没有打到我的应用程序; it's being rejected by nginx.它被 nginx 拒绝。

I have tried configuring AWS to increase the size of the allowed request body based on this answer , to no avail.我已尝试根据此答案配置 AWS 以增加允许的请求正文的大小,但无济于事。

I've tried adding a file at .ebextensions/01_files.config with the contents:我尝试在.ebextensions/01_files.config添加一个文件,其内容为:

files:
  "/etc/nginx/conf.d/proxy.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
      client_max_body_size 20M;

That didn't work, so I tried adding the file directly to .ebextensions/nginx/conf.d/proxy.conf with only:那没有用,所以我尝试将文件直接添加到.ebextensions/nginx/conf.d/proxy.conf中,仅:

client_max_body_size 20M;

And this also didn't work.这也没有奏效。 Then I SSH'ed into the instance and added the file directly.然后我通过 SSH 进入实例并直接添加文件。 Upon re-deploy, the entire conf.d directory was deleted and re-written, without this file.重新部署后,整个conf.d目录被删除并重写,没有这个文件。

How can I get AWS Elastic Beanstalk with Node.js 10 running on 64bit Amazon Linux 2/5.1.0 to accept nginx configuration?如何让 AWS Elastic Beanstalk 与 Node.js 10 在 64 位 Amazon Linux 2/5.1.0 上运行以接受 nginx 配置?

The nginx setting you are trying to use ( /etc/nginx/conf.d/proxy.conf ) is for Amazon Linux 1 .您尝试使用的nginx设置 ( /etc/nginx/conf.d/proxy.conf ) 适用于Amazon Linux 1

Since you are using Amazon Linux 2 you should be using different files for setting nginx.由于您使用的是Amazon Linux 2 ,因此您应该使用不同的文件来设置 nginx。 For AL2, the nginx settings should be in .platform/nginx/conf.d/ , not in .ebextentions as shown in the docs .对于 AL2,nginx 设置应该在.platform/nginx/conf.d/中,而不是在.ebextentions中,如文档中所示。

Therefore, you could have the following .platform/nginx/conf.d/myconfig.conf with content:因此,您可以拥有以下.platform/nginx/conf.d/myconfig.conf内容:

client_max_body_size 20M;

The above is an example only of the config file.以上只是配置文件的一个示例 I can't verify if the setting will actually work, but you are definitely using wrong folders to set nginx options.我无法验证该设置是否真的有效,但您肯定使用了错误的文件夹来设置 nginx 选项。

My recommendation would be to try to make it work manually through ssh as you are attempting now.我的建议是尝试通过 ssh 手动使其工作,就像您现在尝试的那样。 You may find that you need to overwrite entire nginx setting if nothing works by providing your own .platform/nginx/nginx.conf file.如果通过提供您自己的.platform/nginx/nginx.conf文件不起作用,您可能会发现您需要覆盖整个 nginx 设置。

adding the client_max_body_size 20M;添加client_max_body_size 20M; in the folder .platform/nginx/conf.d/proxy.conf fixed it for me.在文件夹.platform/nginx/conf.d/proxy.conf中为我修复了它。 Please make sure to check whether you are using Amazon Linux 2请务必检查您是否使用亚马逊 Linux 2

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM