.Net 5 AWS nginx Linux 弹性 beantalk 变化 client_max_body_size
.Net 5 AWS nginx Linux elastic beanstalk changing client_max_body_size
由于 AWS elastic beanstalk nginx 的默认设置,我无法上传超过 1 兆字节的文件。我在网上查了一下,发现我需要将 client_max_body_size 更改为 client_max_body_size 20M 以允许更大的文件。但是,我没有地方可以这样做。 .net 上没有 Nginx 配置文件。我正在使用 .net 5,然后在 visual studio 19 上使用 aws 工具包将其上传到 elastic beanstalk。我能看到的唯一配置文件是 aws-beanstalk-tools-defaults.json.
{
"region" : "eu-west-2",
"configuration" : "Release",
"framework" : "net5.0",
"self-contained" : false,
"application" : "testapplication",
"environment" : "testapplication-prod-env",
"enable-xray" : false,
"enhanced-health-type" : "basic",
"additional-options" : "",
"proxy-server" : "nginx",
"solution-stack" : "64bit Amazon Linux 2 v2.1.5 running .NET Core",
"environment-type" : "LoadBalanced",
"cname" : "vitradssltest-prod",
"instance-type" : "t3a.nano",
"key-pair" : "my key pair for testing",
"instance-profile" : "aws-elasticbeanstalk-ec2-role",
"service-role" : "aws-elasticbeanstalk-service-role",
"loadbalancer-type" : "classic",
"health-check-url" : "/"
}
由于您使用的是 64bit Amazon Linux 2 v2.1.5 running .NET Core
nginx 默认处于启用状态。因此,我看不出任何自定义 nginx 的标准方法对您不起作用的原因。
具体来说,自定义设置应该在.platform/nginx/conf.d/
中,如docs所示。因此,您可以使用以下内容创建以下 .platform/nginx/conf.d/myconfig.conf
文件:
client_max_body_size 20M;
这已经通过 AWS elastic beanstalk 实现了。虽然你的图像可能不同,但我使用了以下过程:
- 在您的解决方案的根目录添加一个文件夹并将其命名为 '.ebextensions'
- 在该文件夹中,添加一个新文件并将其命名为 '01_nginx.config'
- 更新文件内容如下
在我研究过的类似解决方案中,它看起来像这样:
files:
"/etc/nginx/conf.d/01_proxy.conf":
mode: "000644"
owner: root
group: root
content: |
client_max_body_size 20M;
当您将更改部署到 elastic beanstalk 时,它将从 ebextensions 文件夹中读取并应用所有文件更新。
我有一点乐趣和游戏将它添加到项目中。只需确保此项目组在 .csproj 文件中
<ItemGroup>
<Content Include=".platform\nginx\conf.d\myconf.conf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
如果在发布到 EBS 之后您检查例如
[proj_folder]\obj\Release\net6.0\linux-x64\PublishOutputs.49276aa42a.txt
你应该看到:
bin\Release\net6.0\publish\.platform\nginx\conf.d\myconf.conf
由于 AWS elastic beanstalk nginx 的默认设置,我无法上传超过 1 兆字节的文件。我在网上查了一下,发现我需要将 client_max_body_size 更改为 client_max_body_size 20M 以允许更大的文件。但是,我没有地方可以这样做。 .net 上没有 Nginx 配置文件。我正在使用 .net 5,然后在 visual studio 19 上使用 aws 工具包将其上传到 elastic beanstalk。我能看到的唯一配置文件是 aws-beanstalk-tools-defaults.json.
{
"region" : "eu-west-2",
"configuration" : "Release",
"framework" : "net5.0",
"self-contained" : false,
"application" : "testapplication",
"environment" : "testapplication-prod-env",
"enable-xray" : false,
"enhanced-health-type" : "basic",
"additional-options" : "",
"proxy-server" : "nginx",
"solution-stack" : "64bit Amazon Linux 2 v2.1.5 running .NET Core",
"environment-type" : "LoadBalanced",
"cname" : "vitradssltest-prod",
"instance-type" : "t3a.nano",
"key-pair" : "my key pair for testing",
"instance-profile" : "aws-elasticbeanstalk-ec2-role",
"service-role" : "aws-elasticbeanstalk-service-role",
"loadbalancer-type" : "classic",
"health-check-url" : "/"
}
由于您使用的是 64bit Amazon Linux 2 v2.1.5 running .NET Core
nginx 默认处于启用状态。因此,我看不出任何自定义 nginx 的标准方法对您不起作用的原因。
具体来说,自定义设置应该在.platform/nginx/conf.d/
中,如docs所示。因此,您可以使用以下内容创建以下 .platform/nginx/conf.d/myconfig.conf
文件:
client_max_body_size 20M;
这已经通过 AWS elastic beanstalk 实现了。虽然你的图像可能不同,但我使用了以下过程:
- 在您的解决方案的根目录添加一个文件夹并将其命名为 '.ebextensions'
- 在该文件夹中,添加一个新文件并将其命名为 '01_nginx.config'
- 更新文件内容如下
在我研究过的类似解决方案中,它看起来像这样:
files:
"/etc/nginx/conf.d/01_proxy.conf":
mode: "000644"
owner: root
group: root
content: |
client_max_body_size 20M;
当您将更改部署到 elastic beanstalk 时,它将从 ebextensions 文件夹中读取并应用所有文件更新。
我有一点乐趣和游戏将它添加到项目中。只需确保此项目组在 .csproj 文件中
<ItemGroup>
<Content Include=".platform\nginx\conf.d\myconf.conf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
如果在发布到 EBS 之后您检查例如
[proj_folder]\obj\Release\net6.0\linux-x64\PublishOutputs.49276aa42a.txt
你应该看到:
bin\Release\net6.0\publish\.platform\nginx\conf.d\myconf.conf