我想自定义 NGINX 配置中的“client_max_body_size”值,以便我可以将大文件上传到我的 AWS Elastic Beanstalk 环境。
解决方法
NGINX 默认文件上传限制为 1 MB。要上传大于 1 MB 的文件,请更新 client_max_body_size 值。
**重要事项:**M 和 MB 都表示“兆字节”。例如,2M 等于 2 MB。但是,NGINX 配置仅接受“M”作为有效的语法值。数字和字母“M”之间没有空格。
注意: 要自定义所有 Amazon Linux 2 和 Amazon Linux 2023 平台版本的默认代理配置,请参阅 Extending Elastic Beanstalk Linux platforms。
要在 Amazon Linux 2 和 Amazon Linux 2023 中配置 client_max_body_size 值,请完成下面的步骤:
-
创建名为 client_max_body_size.conf 的 .conf 配置文件,其中包含以下内容:
client_max_body_size 50M;
-
将 .conf 文件 client_max_body_size.conf 复制到应用程序源包中名为 .platform/nginx/conf.d/ 的文件夹中。
注意: Elastic Beanstalk NGINX 配置自动在 .platform 文件夹中包含 .conf 文件。如果源包中不存在 .conf 文件,请确保创建此路径。
以下示例显示了 Java SE 平台上应用程序 zip 文件中 .platform 目录和 .conf 文件的结构。对于所有 Linux 平台,.platform 文件夹必须放在应用程序源包的根目录下。有关捆绑应用程序的更多信息,请参阅所处平台的文档。
~/my-app.zip/
|-- web.jar
|-- Procfile
|-- readme.md
`-- .platform/
|-- nginx/ # Proxy configuration
| `-- conf.d/
| `-- client_max_body_size.conf
- 在 Elastic Beanstalk 环境中部署新的应用程序版本。
- 使用 SSH 登录到在您的 Elastic Beanstalk 环境中运行的 Amazon Elastic Compute Cloud(Amazon EC2)实例。
- 要验证 NGINX 配置语法是否正确以及对 client_max_body_size 值所做的更改是否已应用,请运行以下命令。
$ sudo nginx -T | egrep -i "client_max_body_size"
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
client_max_body_size 50M;
相关信息
Create an application source bundle