8

I followed the advice here to configure the nginx reverse proxy to allow files larger than the default 1mb. So, my code in /.platform/nginx/conf.d/prod.conf looks like this:

http {
  client_max_body_size 30M;
}

However, this seems to have no effect, and nginx still registers an error when I try to upload a file larger than 1mb.

I also tried doing this without the http and braces, as detailed in the accepted answer to this question, like this:

client_max_body_size 30M;

This also had no effect.

I thought it might be necessary to restart nginx after applying the configuration, so I added a file in the .ebextensions directory called 01nginx.config, which looks like this:

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

This also had no effect.

I have seen this question and the above-referenced question, as well as this one. However, they all seem either outdated or non-applicable to an Amazon Linux 2 instance, since none of them mention the .platform directory from the above-referenced elastic beanstalk documentation. In any case, none of their answers have worked for me thus far. So, what am I missing?

adam tropp
  • 674
  • 7
  • 22

4 Answers4

25

I has a similar issue when moving to Amazon Linux 2.

Simply creating a file at .platform/nginx/conf.d/ called proxy.conf with the content below was enough for me.

client_max_body_size 50M;

If you go digging around the main config for nginx you'll see how this file is included into the middle of the file so there's no need to have it wrapped with http.

This is similar to adam tropp's answer, but it follows the example given by AWS

mattchad
  • 366
  • 3
  • 3
  • This works as advertised; this same file can't contain a location block though, which is what I had in mind – febeling Sep 09 '20 at 09:24
  • 16
    For location blocks you can create a file `.platform/nginx/conf.d/elasticbeanstalk/location.conf` where location can be any name. Files in the elasticbeanstalk sub directory are included in a place suitable for location blocks. – Ben Swinburne Sep 18 '20 at 11:20
  • Hi I'm facing the same problem. Could anyone tell me: should I change '.platform' with a value or - if that is the actual name - should I create the .platform folder in the .ebextensions folder? Or something different alltogether? – Gijs Beijer Apr 01 '21 at 09:40
  • Thanks for the research, Ben! Knowing that saved me a lot of heartburn trying to get a public IP on an instance to SSH in and figure out how to add custom Location blocks. – Eric L. Jun 17 '21 at 15:59
  • Still ended up SSHing in: You can override the entire default NodeJS nginx listener by putting in `.platform/nginx/conf.d/elasticbeanstalk/00_application.conf`. This is the only way to modify the default `location /` settings in EBS! – Eric L. Jun 18 '21 at 21:15
  • 5
    I ran into similar issues and wrote a gist on the different ways to manipulate the nginx config. You can find it here: https://gist.github.com/henhan/2943013c9064606425b0ee5bb1ca8c99 – Henrik Hansson Aug 01 '21 at 11:28
  • PERFECT ANSWER; I TESTED AND WORKS; the docs are few and far between on the clarity between Amazon Linux 1 vs 2.. – Snerd Jul 11 '22 at 22:10
3

Below worked for me:

~/my-app/
|-- web.jar
|-- Procfile
|-- readme.md
|-- .ebextensions/
|   |-- options.config        # Option settings
|   `-- cloudwatch.config     # Other .ebextensions sections, for example files and container commands
`-- .platform/
    |-- nginx/                # Proxy configuration
    |   |-- nginx.conf
    |   `-- conf.d/
    |       `-- custom.conf
1

Ok, after many tries, I was able to solve this like so:

Add a file in the .ebextenstions directory called 01_reverse_proxy.config (name doesn't matter, just the .config part I think)

In that file, place exactly this:

files:
  "/etc/nginx/conf.d/proxy.conf" :
  mode: "000755"
  owner: root
  group: root
  content: |
    client_max_body_size 30M;
commands:
  01_reload_nginx:
    command: "service nginx reload"

with proper YAML spacing. This solves the problem on a stack including Rails, Puma, and Amazon Linux 2.11.4. This is NOT the way documented in the elastic beanstalk linux platforms documentation.

adam tropp
  • 674
  • 7
  • 22
  • 8
    This is how to configure it on the older version of Amazon Linux, the higher voted answer is specific to Amazon Linux 2. – Kevin Dahl Nov 11 '20 at 19:48
0

I had the same issue for a few days, and finaly I solved following these steps:

1 Create a file in this route .platform/nginx/nginx.conf

file nginx.conf

events {}

http {
    server {
        listen      80;
        server_name project-jndxpewg.eu-west-2.elasticbeanstalk.com;
        client_max_body_size 64M;

        include /etc/nginx/fastcgi_params;


         # in my case this is the project public folder
        root /var/www/html/webroot;
        index index.php;

        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;

        location / {
            try_files $uri \$uri /index.php?$args;
        }

        location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass  unix:/var/run/php-fpm/www.sock;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

    }
}
R0bertinski
  • 517
  • 6
  • 12