기타

[NGINX]413 Request Entity Too Large 어떻게 해결하지?

stayhungri 2022. 6. 15. 22:43

사진 업로드 API 개발 중 아래처럼 "413 Request Entity Too Large" 에러를 마주했습니다.

로컬에서는 NGINX 없이 테스트해서 문제 없다고 판단하고 개발 서버에 올리니 바로 에러가 나오네요.

NGINX 로그를 살펴보니 이렇게 나옵니다.

2022/06/15 21:09:02 [error] 2518354#2518354: *744366 client intended to send too large body: 1287851 bytes, client: x.x.x.x, server: xxxxxxxxxx.com, request: "POST /api/yyyy/pppp HTTP/1.1", host: "xxxxxxxxxx.com", .....

client 가 매우 큰 바디를 보내려고 해서 생긴 문제라고 합니다.

우분투(ubuntu) 기준으로 vi /etc/nginx/nginx.conf 파일을 아래처럼 수정하면 됩니다.

...
http {

        ##
        # Basic Settings
        ##
        client_max_body_size 100M;
        ....
}
...

 

1M 가 넘는 파일을 업로드하려고 하면 나옵니다. 인터넷을 뒤져보니 NGINX는 기본으로 1M 가 넘는 요청은 제한하고 있네요.

저는 일단 넉넉히 100M로 해주었습니다. 제한을 없애고 싶다면 0으로 셋팅하라고 합니다.

# https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
Syntax:client_max_body_size size;
Default:client_max_body_size 1m;
Context:http, server, location

Sets the maximum allowed size of the client request body. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size  to 0 disables checking of client request body size.

 

참고