skip to Main Content

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

3

Answers


  1. 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;
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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=".platformnginxconf.dmyconf.conf">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>
      </ItemGroup>
    

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

    [proj_folder]objReleasenet6.0linux-x64PublishOutputs.49276aa42a.txt
    

    you should see:

    binReleasenet6.0publish.platformnginxconf.dmyconf.conf
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search