1

I have developed a Django application and deployed it in an Elastic Beanstalk environment (with nginx as proxy server).

The Linux platform should be the first version because if I run the command: cat /etc/os-release in the terminal of the EC2 instance managed by EB I get these information:

os-release file of the EC2 instance

Also I double confirm that it's Linux 1 and NOT Linux 2 by going to the EC2 console:

Linux platform of the EC2 instance

Now, after having clarified which Linux platform I'm using in the EC2 instance, let's go ahead with the problem.

When I access the EC2 instance and I go the file etc/nginx/nginx.conf, what I see is this:

Content of the nginx.conf file

Now, what I want to do is to increase the timeout settings under the "server" section of the nginx.conf file. I also would like to increase the client_max_body_size somehow.

I read from some documentation online the I have to create a .ebextensions folder in the root of my Django project with inside some .config files and also a buildspec.yml file in the root folder of the project.

So this is where I have located my files:

my_project
  |- .ebextensions
  |  |- django.config
  |  |- instances.config
  |  |- nginx.config
  |- buildspec.yml
  |- manage.py
  |...

Here the content of each file:

django.config:

container_commands:
  01_makemigrations:
    command: "source /var/app/venv/*/bin/activate && python3 manage.py makemigrations --noinput"
    leader_only: true
  02_migrate:
    command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate --noinput"
    leader_only: true
  03_collectstatic:
    command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput"
    leader_only: true

instances.config:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: "my_project.wsgi:application" 
  aws:elbv2:listener:443:  
    ListenerEnabled: 'true'  
    Protocol: HTTPS  
    SSLCertificateArns: arn:aws:acm:<region>:<user_id>:certificate/<certificate_id>
  aws:elasticbeanstalk:environment:proxy:staticfiles:  
    /static: staticfiles 
  aws:elbv2:loadbalancer:
    IdleTimeout: 900

nginx.config:

 files:
   "/etc/nginx/conf.d/nginx.custom.conf":
       mode: "644"
       owner: "root"
       group: "root"
       content: |
         client_header_timeout   900;
         client_body_timeout     900;
         send_timeout            900;
         proxy_connect_timeout   900;
         proxy_read_timeout      900;
         proxy_send_timeout      900;
         client_max_body_size    500M;

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

buildspec.yml:

version: 0.2  
  
phases:  
  install:  
    runtime-versions:  
      python: 3.11  
    commands:  
      - echo Installing dependencies...  
      - pip install -r requirements.txt  
  pre_build:  
    commands:  
      - echo Running migrations...  
      - python manage.py migrate --noinput  
  build:  
    commands:  
      - echo Build completed on `date`  
  
artifacts:  
  files:  
    - '**/*'  

But after deploying the application on the Elastic Beanstalk environment I always see the default nginx configuration.

So my question is, how can I change the configuration of the nginx server during deployment in order to increase the following parameters:

  • client_max_body_size 500M;
  • client_header_timeout 900;
  • client_body_timeout 900;
  • send_timeout 900;
  • proxy_connect_timeout 900;
  • proxy_read_timeout 900;
  • proxy_send_timeout 900;
3
  • 1
    can you try adding it under .platform folder instead of .ebextensions. May be you are using Amazon linux 2 or Amazon Linux 2023. And the next thing is the folder structure. It should be as follows if you are using Amazon linux 1. ~/workspace/my-app/.ebextensions/nginx/conf.d/myconf.conf if you are using Amazon linux 2 or Amazon Linux 2023 use the following folder structure. ~/workspace/my-app/.platform/nginx/conf.d/elasticbeanstalk/myconf.conf Commented Jun 26, 2024 at 7:35
  • Perfect, thank you for the answer, indeed I was making confusion with Linux 2023, thinking it was the Linux 1 platform. But instead Linux 2023 is like Linux 2 and therefore the procedure is like the Linux 2 (i.e. using .platform instead of .ebextensions). The Amazon documentatin about this is not very clear Commented Jun 27, 2024 at 8:36
  • Added as an answer so that if anyone who encounters this issue would refer to the answer. Commented Nov 14, 2024 at 11:59

1 Answer 1

2

As per the comment that I added this is basically because of the Amazon Linux version that you use in the elasticbeanstalk environment.

In this case, you are using Amazon Linux 2 or Amazon Linux 2023. So you need to use .platform instead of .ebextensions. if you are using Amazon linux 1, then the .ebextensions would work.

It should be as follows if you are using Amazon Linux 1.

~/workspace/my-app/.ebextensions/nginx/conf.d/nginx.config

if you are using Amazon Linux 2 or Amazon Linux 2023.

~/workspace/my-app/.platform/nginx/conf.d/elasticbeanstalk/nginx.config
Sign up to request clarification or add additional context in comments.

1 Comment

spent a day trying to work thru this! thanks for the answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.