Unable to modify nginx config on CodeBuild deployment to EBS

2

We're using CodeBuild to automatically deploy to EBS. We need to modify nginx with a proxy.conf file containing:

client_max_body_size 20M;

to allow us to upload photos to S3. So far none of the documented methods to do this have worked. I initially attempted the following yaml content in .ebextensions/nginx_files.config:

files:
"/etc/nginx/conf.d/01_proxy.conf":
mode: "000644"
owner: root
group: root
content: |
client_max_body_size 20M;
container_commands:
01_nginx_reload:
command: “systemctl reload nginx”

This had no effect. After more research I discovered the new method for modifying the nginx config on Amazon Linux 2 is creating the conf file within the .platform directory. I tried using both these paths:

./platform/nginx/conf.d/00_proxy.conf
./platform/nginx/conf.d/elasticbeanstalk/00_proxy.conf

The 00_proxy.conf file is created on the EC2 instance in /var/app/staging, but is never copied to /etc/nginx/conf.d or /etc/nginx/conf.d/elasticbeanstalk. The next thing I tried was launching a script from Buildfile to copy the file into the correct place. I can see in /var/log/messages on the EC2 instance that Buildfile runs the script, but gets a permission denied message when attempting to copy. If I execute the cp command with sudo I get errors about needing a root password. How can I get around this permission issue?

jhester
asked 3 years ago639 views
1 Answer
2

I figured it out. I had to change discard-paths from yes to no in the CodeBuild Buildspec file and add a Procfile to the project that pointed to the full path of the jar file. The full .platform directory structure needs to remain intact for the nginx conf files to be able to end up in the correct location within the /etc/nginx directory. This is what I ended up with in the Buildspec file:

artifacts:
files:
- target/myapp.jar
- .ebextensions//*
- .platform/
/*
- Buildfile
- Procfile
discard-paths: no

jhester
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions