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
질문됨 3년 전658회 조회
1개 답변
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
답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠