위와 같은 문제가 발생하는 이유는 Elastic Beanstalk를 이용해 배포할 경우 프록시 서버로 사용되는 Nginx의 client_max_body_size 설정이 1MB로 되어 있기 때문이다.
client_max_body_size: request의 Content_Length 헤더 값이 지정된 용량을 넘지 않도록 설정(악의적인 대용량 파일 업로드를 방지)
client_max_body_size를 설정하는 방법은 2가지이다.
- EC2 Instance Connect로 접속해 직접 값을 설정
- 배포 파일(.zip)에 포함
EC2 Instance Connect로 접속해 설정하기
인스턴스 선택 → [Connect] → EC2 Instance Connect → [Connect]
vi /etc/nginx/nginx.conf
위 명령어를 입력하면 다음과 같은 내용을 볼 수 있다.
http { } 내 다음 명령어를 추가하고 [ESC] → :wq 순으로 입력한다.
http {
client_max_body_size 20M;
}
nginx를 재시작한다.
sudo systemctl restart ngix
배포 파일(.zip)에 포함하기
- .platform/nginx/conf.d/ 경로에 .conf파일을 생성한다.(파일명은 상관 X)
- 예) .platform/nginx/conf.d/client_max_body_size.conf
- .conf 파일 내 client_max_body_size 20M;를 입력하고 저장한다.
- 배포할 .jar 파일과 함께 .platform 폴더를 압축한다.
- Elastic Beanstalk로 배포한다.
배포파일.zip # Elastic Beanstalk에 배포
|-- 배포파일.jar
|-- .platform/
|-- nginx/
|-- conf.d/
|-- xxx.conf # client_max_body_size를 저장하고 있는 파일
참고 자료: https://repost.aws/knowledge-center/elastic-beanstalk-nginx-configuration
'TIL(Today I Learned)' 카테고리의 다른 글
TIL - Spring Boot에서 In-memory Cache 적용 (0) | 2024.07.04 |
---|---|
TIL - Spring Boot Test 시 JPA metamodel must not be empty (0) | 2024.07.03 |
Docker 명령어 1 (0) | 2024.06.28 |
Windows에서 Docker 설치 (0) | 2024.06.27 |
TIL - Entity의 Setter 사용을 지양하기 (0) | 2024.06.19 |