200

I'm running into "413 Request Entity Too Large" errors when posting files larger than 10MB to our API running on AWS Elastic Beanstalk.

I've done quite a bit of research and believe that I need to up the client_max_body_size for Nginx, however I cannot seem to find any documentation on how to do this using Elastic Beanstalk. My guess is that it needs to be modified using an ebetension file.

Anyone have thoughts on how I can up the limit? 10MB is pretty weak, there has to be a way to up this manually.

Nick Parsons
  • 8,377
  • 13
  • 48
  • 70
  • 4
    The default is only 1MB these days... – rogerdpack May 15 '19 at 22:00
  • For the record all of the provided solutions do not tackle .NET deployments. If you use .NET in AWS Elastic Beanstalk you must configure the IIS settings in your project. For me I had to configure the web.config in my net471 app. – SimonH Mar 26 '20 at 20:56

28 Answers28

261

There are two methods you can take for this. Unfortunately some work for some EB application types and some work for others.

Supported/recommended in AWS documentation

For some application types, like Java SE, Go, Node.js, and maybe Ruby (it's not documented for Ruby, but all the other Nginx platforms seem to support this), Elasticbeanstalk has a built-in understanding of how to configure Nginx.

To extend Elastic Beanstalk's default nginx configuration, add .conf configuration files to a folder named .ebextensions/nginx/conf.d/ in your application source bundle. Elastic Beanstalk's nginx configuration includes .conf files in this folder automatically.

~/workspace/my-app/
|-- .ebextensions
|   `-- nginx
|       `-- conf.d
|           `-- myconf.conf
`-- web.jar

Configuring the Reverse Proxy - Java SE

To increase the maximum upload size specifically, then create a file at .ebextensions/nginx/conf.d/proxy.conf setting the max body size to whatever size you would prefer:

client_max_body_size 50M;

Create the Nginx config file directly

For some other application types, after much research and hours of working with the wonderful AWS support team, I created a config file inside of .ebextensions to supplement the nginx config. This change allowed for a larger post body size.

Inside of the .ebextensions directory, I created a file called 01_files.config with the following contents:

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

This generates a proxy.conf file inside of the /etc/nginx/conf.d directory. The proxy.conf file simply contains the one liner client_max_body_size 20M; which does the trick.

Note that for some platforms, this file will be created during the deploy, but then removed in a later deployment phase.

You can specify other directives which are outlined in Nginx documentation.

http://wiki.nginx.org/Configuration

starball
  • 20,030
  • 7
  • 43
  • 238
Nick Parsons
  • 8,377
  • 13
  • 48
  • 70
  • 3
    The file format is documented at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html. The progress is logged at /var/log/cfn-init.log. In the logs you should see something like `2014-xx-xx xx:xx:xx,xxx [DEBUG] Writing content to /etc/nginx/conf.d/proxy.conf`. I'm not sure, but it seemed like restarting the server might be necessary. – h-kippo Dec 11 '14 at 09:12
  • 2
    Working for me with puma. Had to restart service like @Will said though (sudo service nginx reload). – Dennis Jan 17 '16 at 21:37
  • 1
    Hopefully this might help someone else as it took me a while... indentation is important - it has to conform the the YAML spec - https://docs.saltstack.com/en/latest/topics/yaml/ – alexs Jun 04 '17 at 21:35
  • 1
    Confirmed working, make sure `.ebextensions` is not in `.ebignore` and `.gitignore` I did not need to restart nginx service, `eb deploy` and it worked – GabLeRoux Mar 29 '18 at 17:54
  • Note that for Java/Go/maybe other applications, you can just create the file at `.ebextensions/nginx/conf.d/proxy.conf`. If you try to use this method on those apps, the configuration file is created, but then later replaced during the deployment phase. – Daniel Compton May 24 '18 at 02:44
  • This is not working for me, I created a post https://serverfault.com/questions/925766/elasticbeanstalk-customize-nginx-through-ebextension – psabbate Aug 10 '18 at 14:23
  • 5
    For node js, the second method (files: ) worked for me. The first one did not work. Even AWS support advised to use the second method for node js https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html – Kapil Aug 17 '18 at 14:30
  • This is a great solution but looks like at this time it wont't work for other stacks like Ruby. Just tested it now. – fagiani Aug 20 '18 at 18:58
  • 1
    For me (java Procfile style) only the first method worked, with the second method my files /etc/nginx/conf.d/xx.conf would always be deleted for some reason... – rogerdpack May 15 '19 at 21:58
  • 2
    I have just tested both options for ElasticBeanstalk + Java8 environment and the first one worked for me. The second one didn't. Hope it helps!. – Rafael Larios May 20 '20 at 21:49
  • Note that if you are using a docker image with EB, you need to include your .ebextensions folder in the source bundle zip together with the Dockerrun json file. Took me a while to figure that out, so I'm posting it in case someone else has the same issue. – Adam Aug 22 '20 at 01:06
  • This did not work for me on Python (Flask). Jijo Cleetus' response worked. – Dave Bowman Oct 04 '20 at 16:31
  • I can confirm that the first solution does not work for a NodeJs express app. The second approach instead, works fine! – ReactiveMax Aug 03 '21 at 15:30
  • 10
    For anyone looking, the correct Nginx conf path for Python on Elastic Beanstalk Amazon Linux 2/3.3.1 is `.platform/nginx/conf.d/proxy.conf` – Evan Byrne Aug 04 '21 at 17:42
169

I have tried all .ebextensions method of adding implementation level configuration and it didn't helped me in the latest Amazon Linux AMI. I have did a lot research and after going through the logs i can find the deployment task runner is checking for a folder called .platform everytime and i thought of add one just like the .ebextensions. Below is the settings i have done in my root folder of my project.

Add the below folder setup in the root level of your project folder.

Folder structure (.platform/nginx/conf.d/proxy.conf)

.platform/
         nginx/
              conf.d/
                    proxy.conf
         00_myconf.config

Content of File 1 - proxy.conf (Inside .platform/nginx/conf.d/ folder)

client_max_body_size 50M;

Content of File 2 - 00_myconf.config (Inside .platform/ folder)

container_commands:
  01_reload_nginx:
    command: "service nginx reload"

Care full with the extensions. First file is .conf and second file is .config.

Now redeploy your project to Amazon Elastic Beanstalk and you will see the magic. This configuration will be added to all your EC2 instances, created as part of auto scaling.

Detailed folder structure below.

enter image description here

Jijo Cleetus
  • 2,679
  • 1
  • 11
  • 17
  • 25
    Man!!!!!!!! Thank you so much. This is the only way to set nginx config in AWS EB Amazon linux. I wasted a whole day trying every available solution!!! I cant express how to to thank you for taking the time to write this answer in detail. Bless you. If you have some kind of patreon or buymeacoffee account Il contribute. @jijo Cleetus – InfinitePrime Jun 24 '20 at 14:41
  • 12
    Thanks a lot. I too tried all possible approaches using `.ebextensions` and only this approach worked. – ArunDhaJ Jun 25 '20 at 06:04
  • 3
    Thanks a lot, this worked for a Spring Boot application too; with Elastic Beans Talk running tomcat. Have a beer on my tab :) . – Awi Aug 03 '20 at 22:48
  • 6
    Has anyone found any reference to this in the AWS docs? – ionutab Aug 11 '20 at 08:18
  • 3
    After trying all other solutions, this one appears to be the most recent correct way to do it – vIceBerg Aug 11 '20 at 18:18
  • 2
    Yeah. I wandered many days recently but this only works. In my case, Nginx reload was not necessary. – Kim-Jimin Sep 02 '20 at 08:22
  • 1
    After trying thousands of different ways to implement .ebextensions, I've tryied your solution (using .platform) and worked perfectly, thanks for your help! – Rene Polo Sep 12 '20 at 17:59
  • 10
    Nice work. This is documented by AWS but very poorly. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html. See Reverse proxy configuration section. "All Amazon Linux 2 platform versions use nginx as their default reverse proxy server....To extend the Elastic Beanstalk default nginx configuration, add .conf configuration files to a folder named .platform/nginx/conf.d/ in your application source bundle" – F_SO_K Sep 24 '20 at 10:21
  • 2
    I've spent all morning trying, even this answer didn't fix it for me. I've given up and switched to an Apache reverse proxy, which doesn't have the low file limit by default. – F_SO_K Sep 24 '20 at 12:19
  • @F_SO_K thanks for the information on reverse proxy, will try that. I am sorry to hear that you gave up on this. Please go through the logs and try to resolve at least in your spare time – Jijo Cleetus Sep 24 '20 at 15:35
  • 1
    Thank you so much!!! It works. I just changed folder .platform/nginx/conf.d/proxy.conf to .platform/nginx/conf.d/elasticbeanstalk/proxy.conf for python. And works!!! – marlonjd Sep 28 '20 at 14:11
  • This should be the accepted answer now(the year 2020). I think the accepted answer is old and doesn't work anymore. – Bishwajyoti Roy Oct 28 '20 at 21:33
  • 2
    Worker perfectly! if using docker make sure to add the `.platform` folder in the root with `Dockerrun.aws.json` and bundle as `.zip` – M. Abreu Nov 24 '20 at 22:39
  • 1
    Thank you! I only needed the proxy.conf to get it working. Presumably `eb deploy` restarts nginx … – aclark Dec 27 '20 at 23:46
  • 1
    worked also for me! Python / Django with Dockerized Image on Amazon Linux 2 platform. The accepted solution did not work for me :-( – Michael Boesl Apr 04 '21 at 19:28
  • @M.Abreu Do you mind to share how this can be done using docker? How do i bundle it as zip? – Yen Sheng May 25 '21 at 15:07
  • 1
    end up including ```.platform/**/*``` in my buildspec.xml artifacts so that my docker image works – Yen Sheng May 25 '21 at 16:10
  • This one worked for me on a PHP/Nginx stack. Tried lots of the other suggestions but this is one that ended up working for me. Thanks! – peeldog Sep 06 '21 at 19:12
  • 1
    How do you know that the config is effected? – TuracBey Sep 07 '21 at 15:26
  • 1
    is the `00_myconf.config` required? – alext Sep 10 '21 at 19:53
  • 1
    @AleksandarT that i have added for a backup, This will work without it, since the new instance spawning will initiate nginx reload. – Jijo Cleetus Sep 14 '21 at 19:07
  • 1
    Thank you so much, I spend 3 days for solve this issue, many answer are there but no one said that how to do changes in aws elastic beanstalk, But you explain very well with all the points – Sanjayrajsinh Nov 05 '21 at 16:27
  • 1
    This solution works perfectly for NodeJs. The marked solution is outdated it seems. – Rasool Khan Nov 09 '21 at 07:39
  • 1
    Thank you @JijoCleetus! Fixed the issue for CodeStar Django – Majali Feb 06 '22 at 09:15
  • Does this also work for a Spring Boot application which is deployed as a JAR? – Captai-N Apr 09 '22 at 06:20
  • 1
    I just ran into this issue myself and it seems like AWS EB is changing the directory structure every day. As of right now, your custom configuration is supposed to go in `.platform/nginx/conf.d/elasticbeanstalk/` – Hamed Apr 17 '22 at 16:57
  • @Hamed - how did you figure that out? Did you find documentation somewhere? – reactFullStackDeveloper May 11 '22 at 20:55
  • 1
    @reactFullStackDeveloper I had to ssh into my instance and start digging around in the nginx configuration to find it. – Hamed May 12 '22 at 15:42
  • 1
    I am using ebs, this one works. Thank you!!! – Frank Guo Apr 11 '23 at 11:41
55

When using Amazon Linux 2 (regardless of platform)

The accepted answer is correct when you're using an older Elastic Beanstalk environment using Amazon Linux AMI. Newer Elastic Beanstalk environments use the Amazon Linux 2 AMI.

When using Amazon Linux 2 you need to specify the custom Nginx config in the .platform/ directory instead of the .ebextensions/.

This means that you'll need to create the file .platform/nginx/conf.d/proxy.conf with the content client_max_body_size 50M; instead.

The .platform/ directory was also mentioned in another answer, but that still required reloading the Ngix config, with Amazon Linux 2 reloading is no longer needed.

You can find more options about this in the Extending Elastic Beanstalk Linux platforms documentation.

JanDintel
  • 999
  • 7
  • 11
  • 4
    Worked for Amazon Linux 2 and Node.js! – dhollenbeck May 27 '21 at 13:50
  • 3
    Remember to include `.platform/*` alongside the rest of your source files in your source bundle. – Kieran Aug 16 '21 at 13:25
  • important takeaway by @Kieran, in my example with Java Spring Boot i had to create the zip of the jar and `.platform/*` folder together on the same level – alext Sep 10 '21 at 19:49
  • @JanDintel the other `.platform` answer and your are kinda not aligned on reloading the Nginx config. So at the end the reloading of the config is not needed and is done by AWS? – alext Sep 10 '21 at 19:56
  • 1
    @AleksandarT it's no longer needed to add an after hook to reload the Nginx config when using this method – JanDintel Sep 29 '21 at 14:15
  • Encoding: JanDintel's solution worked for me. Though I had to pay attention to the encoding und change the default utf8bom (windows & visual studio code?) to utf8. Only then the .conf file with finally copied to the correct folder. – raw Apr 21 '22 at 22:17
  • Some notes I found. This worked for tomcat based elastic beanstalk but there are some key differences from Amazon linux 1.0 vs 2.0. 1. In 1.0 you could have your .ebextension file in either the Root director or inside META-INF the .platform directory must be at root level to function. 2. Files under the path .platform/nginx/conf.d/ get included in your http block of your nginx.conf, for me this had no impact on my uploads. To get the configuration in the server block of the nginx.conf you must use the following path .platform/nginx/conf.d/elasticbeanstalk/ – lvoelk Jul 11 '22 at 18:26
  • This worked for me for a node js app in the docker platform. But didn't work for a spring boot app – Ramjan Ali Aug 25 '22 at 13:42
37
files:
    "/etc/nginx/conf.d/proxy.conf" :
        mode: "000755"
        owner: root
        group: root
        content: |
           client_max_body_size 20M;

Modified the above answer for the sake of security (and the syntax was wrong, see, two 'owner:' entries in the YAML), guys, please don't set 777 permissions on ANYTHING. Unless you enjoy being hacked, and set the owner of Nginx config files to root.

Also see the below answer to make nginx pickup this change after deployment.

Raj
  • 22,346
  • 14
  • 99
  • 142
user3217794
  • 379
  • 3
  • 2
23

EDIT: After you've deployed a build with the instructions in the accepted answer by Nick Parsons, you may need to restart the nginx server to pick up the changes.

To do this, ssh to the instance and do

sudo service nginx reload

To learn more about reloading, see http://nginx.org/en/docs/beginners_guide.html.

In a previous version of Elastic Beanstalk, I was able to add a container_command to accomplish this, but now I am finding, like @cdmckay, that this causes a deployment failure. If you rebuild your environment it will pick up the client_max_body_size settings as well as long as that instruction is in your config file.

Will
  • 2,768
  • 1
  • 17
  • 15
  • Is this necessary? If you don't add this, how will it restart? – cdmckay Apr 27 '15 at 23:05
  • In my experience I found this necessary. – Will Apr 29 '15 at 05:06
  • @cdmckay can you say more about the instance issues the reload command caused? – Will May 17 '15 at 22:14
  • I didn't look into it too closely, but it basically prevented my server from launching until I removed it. It doesn't appear to be necessary. – cdmckay May 18 '15 at 19:38
  • 3
    in my experience i found this was necessary however, I had to add a check to see if nginx was running before trying to restart it for new instances - 'pgrep nginx && service nginx reload || true' – alexs Jun 17 '17 at 10:36
  • The answer from @ConorB better describes how to restart nginx after this config is in place. – Tom Harvey Oct 31 '18 at 09:28
19

The accepted answer didn't work for me since I have a JVM-based app and it seems to do NGINX configuration differently. I would see a proxy.conf file being created during the deploy but then later deleted before the deploy was completed. AWS documentation explains how to configure the proxy:

Create an .ebextensions/nginx/conf.d/proxy.conf file that contains just the line: client_max_body_size 40M;

Daniel Compton
  • 13,878
  • 4
  • 40
  • 60
Raymond26
  • 590
  • 1
  • 7
  • 14
  • 2
    Unfortunately, that didn't work for me (single-container *Docker* ELB) - not even after a reboot of the instance. Logging in to the instance via SSH there is no proxy.conf file being created in `/etc/nginx/conf.d/` – Udo G Mar 07 '17 at 08:03
  • I'm assuming it's because of the fact you're using a Docker ELB and it does nginx conf differently. My answer is for Java-preset ELB. – Raymond26 Mar 08 '17 at 08:24
  • I am using elb and java app. Works for me! Thanks! – Dimitar Vukman Dec 29 '17 at 14:25
  • How can you see the proxy.conf file being created, just noting its temporary presence? – rogerdpack May 15 '19 at 21:59
  • this works for Amazon Linux 1 (legacy instances only), for Amazon Linux 2, change `ebextensions` to `.platform` – alext Sep 10 '21 at 19:54
19

Super Simple Solution for Amazon Linux 2:

  1. On the same level as .ebextensions and .elasticbeanstalk, create a directory called .platform
  2. Create a file (full path shown) under this directory called: .platform/nginx/conf.d/client_max_body_size.conf
  3. Add this one line to the client_max_body_size.conf file: client_max_body_size 20M;
  4. Deploy!!

This is based on AWS NGINX "Reverse proxy configuration" Documentation.

(This worked w/ Django 3.1.4 + Python 3.7 running on 64bit Amazon Linux 2/3.2.0)

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Nerdhappy
  • 303
  • 2
  • 4
9

Following on from the accepted answer, you need may need to reload the nginx config file.

In order to do this add the following command

   container_commands:
      01_reload_nginx:
        command: "service nginx reload"

This would be better practice than ssh'ing into your eb instance and manually doing it with a command.

This combined with the accepted answer solved the same issue for me. (Rails, Puma, NGINX)

Conor
  • 3,279
  • 1
  • 21
  • 35
9

The only thing that worked for me was to create a ".config" file inside .ebextensions like this:

.ebextensions/
           proxy.config

with only this content in the .config file:

files:
  "/etc/nginx/conf.d/proxy.conf":
     content: |
       client_max_body_size 50M;

no need for subfolders, no need to restart the application server, pay attention that is a ".config" not a ".conf" file inside .ebextensions and the use of proper indentation to avoid errors in the aws console the rest is the same doesn't matter the name of the file,

thanks to : http://kroltech.com/2014/09/14/quick-tip-increase-upload-size-in-aws-elastic-beanstalk-node-js-env/

Ed Vieira
  • 183
  • 2
  • 6
8

The accepted answer did not work for me, so instead I overrode the nginx configuration with my own.

I created a file called nginx.conf under the directory .ebextensions/nginx/

I SSHed into a running instance of my Beanstalk app, and copied the contents of the nginx.conf file, using cat /etc/nginx/nginx.conf and copying from the terminal.

I pasted the contents into the nginx.conf file I previously created in .ebextensions/nginx/, and modified the http directive to include client_max_body_size 50M;. I finally redeployed my app using eb deploy and it worked. You should get the following message during deployment:

INFO: Nginx configuration detected in the '.ebextensions/nginx' directory. AWS Elastic Beanstalk will no longer manage the Nginx configuration for this environment.

These are the contents of my .ebextensions/nginx/nginx.conf file:

# Elastic Beanstalk Nginx Configuration File

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    33193;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default     "upgrade";
    }

    server {
        listen        80 default_server;
        access_log    /var/log/nginx/access.log main;

        client_header_timeout 60;
        client_body_timeout   60;
        keepalive_timeout     60;
        gzip                  off;
        gzip_comp_level       4;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;
    }

    client_max_body_size 50M;
}

I did not have to restart the nginx service nor the environment.

Note: Make sure your .ebextensions is part of the .zip file created and uploaded to Beanstalk during deployment (it's not ignored in .gitignore or .ebignore if you're using it).

kkyr
  • 3,785
  • 3
  • 29
  • 59
  • Thanks for this! I was wondering which platform you were using though? For some reason Beanstalk isn't detecting my ` .ebextensions/nginx/nginx.conf` file even though it's in the zip file and git repo. – Icid Mar 29 '18 at 14:16
  • Upvoted for the note. I was ignoring the `.ebextensions` which caused the accepted and popular answer to fail. I did not try everything else you mentionned, but thanks for the note – GabLeRoux Mar 29 '18 at 17:50
  • Can it be used for Node.js running on 64bit Amazon Linux? – Tan Dat Oct 06 '21 at 07:31
5

This is the AWS provided solution, and it works (adjust the size to your needs)

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/enact/12_add_nginx_configuration.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      /bin/echo "client_max_body_size 50M;" > /etc/nginx/conf.d/proxy.conf
      /sbin/service nginx reload
Tony BenBrahim
  • 7,040
  • 2
  • 36
  • 49
5

For those who are stumbling on here:

I followed Jijo Cleetus answer but did not work, but definitely pointed to the right direction.

But I am wordering why because if I see nginx.conf file, it does contain include conf.d/*.conf so it should include the proxy file as the answer mentioned.

Also the default server listening on 80 and marked as default_server, has include conf.d/elasticbeanstalk/*.conf

But this answer did solve the issue, in gist, the .conf files directory have to be .platform/nginx/conf.d/elasticbeanstalk instead of .platform/nginx/conf.d/.

So:

.platform/nginx/conf.d/elasticbeanstalk/01-request-body.conf .platform/nginx/conf.d/elasticbeanstalk/02-timeouts.conf

are some examples

I also confirmed it by logging into the ec2 instance and running nginx -T which prints the running config to verify if my custom configs were included.

Also there I saw, the default application proxy config is named 00_application.conf and nginx includes files in alphabetical order, so named it by prefixing numbers.

Added notes to those who are deploying via CodePipeline: Make sure to include .platform/**/* in buildspec.yaml -> artifacts section

Anubhab Maji
  • 520
  • 7
  • 9
  • 1
    Thank you, this allowed me to replace the stock 00_application.conf that Elastic Beanstalk uses for an Nginx forward proxy for ASP.NET Core web apps. I had to also add the file to the ASP.NET Core project in Visual Studio as well otherwise it's not published (make sure you see it included in the bin/Release folder and also in the deployed zip uploaded to S3). – Stuart Welch May 06 '21 at 17:50
  • 1
    I was deploying using code pipeline and your awesome guidance of adding the artifacts for .platform solved the issue. – Mandeep Singh Sep 04 '21 at 12:22
4

After 3 long days of trying to figure this one out, I jumped on a call with the amazing AWS support team and they gave me some clues about how to solve it. First, my project is in JAVA and I use maven and spring boot to run it through Elastic Beanstalk (EBS).

  1. As explained on AWS' documentation, you need to have the custom nginx settings stored in the root level of your project. To do that I have created a client_max_body_size.conf file and placed it in the following path: myprojectname/src/main/resources/ebextensions/nginx/conf.d/client_max_body_size.conf This file contains only the following line:

    client_max_body_size 10M;
    
  2. Configure maven to add this file in the root folder of my project during the build. This was a bit tricky, I needed to add the following configuration (source) in my POM.xml:

    <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/target/.ebextensions</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources/ebextensions</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
    

  3. You can now already build your project locally and run the following SSH command to validate it's actually located in the root of your project:

    jar tf main-1.0-SNAPSHOT.jar | grep .ebextensions
    
  4. Now it's the tricky part. When you upload it to EBS, your file should contain only the SNAPSHOT.jar file and the .ebextensions folder. For example, if now you will zip the jar file and the folder and upload it manually, it will work!

  5. Since I am using Jenkins for my deployment, and specifically the AWS EBS Deployment Plugin - you need to change the settings of the files/folder you include in the deployment. Now for some reason I wasn't able to include the .ebextensions folder so I just excluded everything else except the folder and the .jar file. enter image description here

This works!

Yanir Calisar
  • 475
  • 4
  • 7
4

If you are running EC2 and installed nginx yourself, your best solution is to create a new file in

/etc/nginx/conf.d

folder:

sudo nano /etc/nginx/conf.d/proxy.conf

and then add the following line there:

client_max_body_size 20M;

then save and restart nginx:

sudo systemctl restart nginx
Aerodynamika
  • 7,883
  • 16
  • 78
  • 137
  • 1
    This is a work around but incase Elastic Beanstalk creates a new instances, you need to give this configuration in each instances. And it is practically not possible since we need to constantly monitor the EC2 intances and nginx restart process is not good everytime – Jijo Cleetus May 21 '20 at 20:22
  • 1
    Thanks this worked for me. Found your solution after 2 hours of headache. – Wikki Jun 13 '22 at 13:27
3

For Golang without Docker I followed these instructions from aws doc:

Configuring the Reverse Proxy

If you want to include directives in addition to those in the nginx.conf http block, you can also provide additional configuration files in the .ebextensions/nginx/conf.d/ directory of your source bundle. All files in this directory must have the .conf extension. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html#go-complex-apps

I created the file proxy.conf in .ebextensions/nginx/conf.d/ at the root of my project, with simply 1 line inside:

client_max_body_size 20M;

If it still doesn't work, make sure .ebextensions folder and sub-folders are included in your deployment zip. No need to restart Nginx manually.

pascal
  • 757
  • 1
  • 7
  • 8
3

I was struggling with the same issue but wasn't able the resolve it, finally its working.

here is my congfig file,

files:
  "/etc/nginx/conf.d/01_proxy.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
      client_max_body_size 50M;
      client_body_buffer_size 16k;

container_commands:
  01_reload_nginx:
    command: "sudo service nginx reload"

The issue was,

I was using a python script for code pipeline which does not include the .ebextensions folder while creating the build.

Here are my few cents,

  1. make sure that your .ebextensions folder is included in your build's zip folder which is located in s3bucket of your aws account
  2. make sure it is not in the .gitignore file
  3. if you are using a script to generate the build make sure it includes .ebextensions
harshal jadhav
  • 5,456
  • 2
  • 18
  • 26
3

Late to the party but for .NET Core the following solution works:

Make a file in /.platform/nginx/conf.d/proxy.conf with the content:

client_max_body_size 100M;

Make sure in properties on Visual Studio that Copy to output directory is set to "Always" for this file and that the build action is "content."

Shaun
  • 101
  • 1
  • 7
  • 1
    Thanks! Copy to output directory is set to "Always" for this file and that the build action is "content." was what I was missing :) – trees_are_great Oct 01 '22 at 15:03
3

Any of the above options may or may not work,

...but if you're line endings of the proxy.config file are not correct then AWS will just error when trying to deploy your code to the instance.

We created the .platform/nginx/conf.d/proxy.config file, but because we are developing and building the code on a windows platform, the line endings were set to Windows (CRLF).

But our AWS instances were all Linux, which expect the Unix (LF) ending.

So when Linux tried to read the file it just failed...it didn't even give us a decent error in the events or logs, it just said failed.

Maybe a last thing to check if nothing else works :)

peter.swallow
  • 905
  • 14
  • 38
2

Alternatively you could change the proxy server to Apache. To do this, go to the Configuration and Edit the Software Configuration. The first option here is “Proxy server”, select “apache”.

David Smits
  • 113
  • 1
  • 3
2

For Spring Boot / Java / Fat-Jar deployments on AWS Beanstalk:

The previous answer using .platform is required in AWS Linux 2, but, unlike .ebextensions, you can't include the .platform directory inside the fat jar - it must be outside the Java jar.

This useful post describes how to set up Maven to create an AWS fat jar for deployment.

https://www.coderdreams.com/deploying-spring-boot-app-to-aws-beanstalk-with-nginx-customization/

Note: there's no need to create a script to restart the nginx server as in the previous answer.

Locutus
  • 444
  • 4
  • 12
  • The linked answer includes so extra steps that are superfluous see my comment on the article. – lvoelk Jul 11 '22 at 18:36
1

For Java Platform

To create the NGINX config proxy file you should just add

.ebextension/nginx/conf.d/proxy.conf file

with the content client_max_body_size 20M; in it.

"proxy.conf" will be deployed to "/etc/nginx/conf.d/proxy.conf" and automatically included by the NGINX config.

Lyudmyla
  • 515
  • 4
  • 8
1

In addition to client_max_body_size, I had to add client_body_buffer_size. Here is the dot config file that worked, for a 2 MB attachment:

files: "/etc/nginx/conf.d/proxy.conf" :
mode: "000755"
owner: root
group: root
content: |
proxy_buffering on;
proxy_buffer_size 128k;
proxy_buffers 8 256k;
client_body_buffer_size 2M;
proxy_busy_buffers_size 256k;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
client_max_body_size 3M;

Norm
  • 109
  • 1
  • 7
1

Creating a file in the .ebextensions directly is the only method I found that has worked for me. Create a new file called 01_files.config and paste in the following:

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

This will create a config file for you on deploy that sets the client_max_body_size to 20MB (change the # to suit your needs).

JasonZ
  • 66
  • 3
1

Had a lot of trouble with this even trying all of the solutions here. I got the error message: unknown directive "client_max_body_size" in the eb-engine.log

This page help me solve the issue: https://forums.aws.amazon.com/thread.jspa?threadID=334637

Visual Studio had create the file in some encoding that caused the problem and I could save/convert the file to ANSI encoding and it worked as expected.

Hope this can help someone stuck with the same problem.

moccasine
  • 23
  • 5
1

Used .platform instead of .ebextensions and all are okay enter image description here

and here is the content of myconf.conf client_max_body_size 400M;

Mhd Wael Jazmati
  • 636
  • 9
  • 18
0

for anyone looking, I had to ssh into my nginx instance and realized the name of my .conf file is nginx.conf, so while creating the file within your project, it may be required to name the file thesame name as is on the server, in my case nginx.conf. I did not bother renaming and redeploying to see if it works, since i was already in on the server, i made the changes to the file right there on the server, reloaded the nginx instance by running "sudo service reload nginx" and the 413 error went away.

Kalu Ngozi
  • 11
  • 2
0

for me the following worked: create a file at: your_app/.platform/nginx/conf.d/01_nginx_proxy.conf which only has the following content/text: client_max_body_size 5M;

(using nodejs next app)

rezan21
  • 1,065
  • 10
  • 14
-2

Create Auto configuration for Nginx in EBS

Since the EBS is auto scaling we can’t increase the Size and request time out manually so we have to add conf file in you source code which automatically include in the nginx configuration in EBS

https://akshaykrisonz.medium.com/fix-413-request-entity-too-large-nginx-error-on-aws-elastic-beanstalk-via-ebs-configuration-7533ad28ac06