Elastic Beanstalk에서 ‘client_max_body_size’를 수정하도록 nginx 구성을 사용자 지정하려면 어떻게 해야 하나요?

2분 분량
0

’413 Request Entity Too Large’라는 오류 메시지를 받지 않고 AWS Elastic Beanstalk 환경에 대용량 파일을 업로드하고 싶습니다.

간략한 설명

기본적으로 NGINX는 파일 업로드에 대해 1MB로 제한됩니다. 요청 크기가 구성된 값을 초과하는 경우 413 Request Entity Too Large 오류가 반환됩니다. 1MB보다 큰 파일을 업로드하려면 NGINX 구성 파일에서 client_max_body_size 지시문을 구성하세요.

중요: M과 MB는 ‘메가바이트’를 나타내는 동일한 표현입니다. 예를 들어 2M는 2MB와 같습니다. 그러나 구성 파일에서는 MB가 유효하지 않으므로 M 단위만 사용하세요.

해결 방법

Amazon Linux 2 환경에서 client_max_body_size를 구성하려면 다음을 수행하세요.

1.    Elastic Beanstalk 기본 NGINX 구성을 확장하려면 다음을 포함하는 .conf 구성 파일 client_max_body_size.conf를 추가합니다.

client_max_body_size 50M;

참고: 앞의 예에서는 client_max_body_size 값이 50M으로 업데이트되었습니다. 요구 사항에 따라 50 대신 임의의 값을 대체하세요.

2.    .conf 구성 파일 client_max_body_size.conf를 애플리케이션 소스 번들의 **.platform/nginx/conf.d/**라는 폴더에 복사합니다. Elastic Beanstalk NGINX 구성에는 이 폴더에 .conf 파일이 자동으로 포함됩니다. 소스 번들에 이 경로가 없는 경우 이 경로를 생성해야 합니다. 다음 예에서는 애플리케이션 zip 파일에 있는 .platform 디렉터리와 .conf 파일의 구조를 보여 줍니다.

-- .ebextensions
       -- other non nginx server config files
            
-- .platform
       -- nginx
           -- conf.d
                 -- client_max_body_size.conf
                   
-- other application files

client_max_body_size.conf 파일의 경로는 다음과 같습니다. my-app/.platform/nginx/conf.d/client_max_body_size.conf.

3.    코드와 새로운 .platform/ 디렉터리를 함께 Elastic Beanstalk 환경에 새 애플리케이션 버전으로 배포합니다.

4.    배포가 완료되면 Elastic Beanstalk 환경에서 실행 중인 인스턴스에 로그인합니다. 로그인한 후 NGINX 서버의 설정이 적용되었는지 확인합니다. 이를 수행하려면 다음 명령을 실행하세요.

$ sudo nginx -T | egrep -i "client_max_body_size"
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
client_max_body_size 50M;

AWS 공식
AWS 공식업데이트됨 일 년 전
댓글 없음