3

I am unable to upload a file above 1 megabyte due to the default setting on AWS elastic beanstalk nginx. I have looked online and I have found out that I need to change the client_max_body_size to client_max_body_size 20M to allow for larger files. However, there is no where for me to do this. There is no Nginx config file on .net. I am using .net 5 and I then use aws toolkit on visual studio 19 to upload it to elastic beanstalk. the only config file that I can see is the 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"     : "/"
}

01_nginx.config'

file location

GolfBravo
  • 837
  • 2
  • 12
  • 23

3 Answers3

3

Since you are using 64bit Amazon Linux 2 v2.1.5 running .NET Core nginx is on by default. Thus, I don't see any reason why standard way of customizing nginx wouldn't work for you.

Specifically, the custom settings should be in .platform/nginx/conf.d/ as shown in the docs. Therefore, you can create the following .platform/nginx/conf.d/myconfig.conf file with the content:

client_max_body_size 20M;
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • I did try it this way around, however, you have to keep reconfiguring the config file if i re-upload new code onto elastic beanstalk. It doesn't remember the client_max_body_size 20M; – GolfBravo Oct 13 '21 at 19:23
  • @GolfBravo Yes that's how eb works and this is by design. Reconfiguration is done automatically by eb so you don't have to worry about that. – Marcin Oct 13 '21 at 20:13
  • Isn't there a way to add the client_max_body_size 20M; to a configuration file at the .net source bundle? The problem I am having is I can not find any source bundle files for .net as its done automatically with visual studio. I really don't want to have to manually update the config file every time there is new deployment. – GolfBravo Oct 13 '21 at 20:36
  • @GolfBravo The .platform/nginx/conf.d/myconfig.conf should be part of your source code bundle. You don't have to do anything manually if you add this file to your code. – Marcin Oct 13 '21 at 20:47
  • There's no files or folders that contain the source code bundle. I think it gets automatically created by visual studio behind the scenes and never shown. I can't find anything that has a file or folder called .platform or linux. the only file that I can see is aws-beanstalk-tools-defaults.json – GolfBravo Oct 13 '21 at 21:10
  • @GolfBravo Maybe you have to make new question explaining exactly how are you deploying your application. A zip bundle must be created somewhere. That's how EB works. Whatever your deployment process is, you have to update it to add `.platform/nginx/conf.d/myconfig.conf ` to the zip. – Marcin Oct 13 '21 at 21:20
  • @GolfBravo How did it go? Did you manage to add `.platform/nginx/conf.d/myconfig.conf ` to your source code? – Marcin Oct 15 '21 at 02:27
  • Thank you for checking up. I'm still trying to make it work. I'll give it a few more days and let you know how it goes. – GolfBravo Oct 15 '21 at 22:27
  • @GolfBravo The other alternative is to create custom EB AMI. This way you don't need to modify your source code, as your EB will be using your AMI tailored to your needs, which includes nginx settings. – Marcin Oct 16 '21 at 00:47
0

This has been achieved before with AWS elastic beanstalk. Although your image may be different, I used the following process:

  • Add a folder at the root of your solution and name it '.ebextensions'
  • Inside that folder, add a new file and name it '01_nginx.config'
  • Update the contents of the file to the following

In a similar solution I worked on, it looked like this:

files:
 "/etc/nginx/conf.d/01_proxy.conf":
  mode: "000644"
  owner: root
  group: root
  content: |
    client_max_body_size 20M;

When you deploy the change to elastic beanstalk, it will read from the ebextensions folder and apply all file updates.

Calvin
  • 61
  • 6
  • 1
    I tried doing what you have said, however, I'm still getting an error message of Request Entity Too Large 403. I have print screened the config file and the location. – GolfBravo Oct 20 '21 at 17:11
0

I had a bit of fun and games adding it to the project. Just ensure this item group is in the .csproj file

 <ItemGroup>
    <Content Include=".platform\nginx\conf.d\myconf.conf">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

If after publishing to EBS you then check e.g.

[proj_folder]\obj\Release\net6.0\linux-x64\PublishOutputs.49276aa42a.txt

you should see:

bin\Release\net6.0\publish\.platform\nginx\conf.d\myconf.conf
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155