티스토리 뷰

반응형

nginx를 사용하는 환경에서 웹 파일 업로드시 413 Request Entity Too Large가 발생되는 경우가 있습니다.

 

원인은 nginx의 기본 body size가 1M이기 때문에 이보다 큰 용량을 요청할 경우 발생되는 에러입니다.

 

client_max_body_size를 늘리면 문제를 해결할 수 있습니다.

 

https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size

 

Module ngx_http_core_module

Module ngx_http_core_module Directives Syntax: absolute_redirect on | off; Default: absolute_redirect on; Context: http, server, location This directive appeared in version 1.11.8. If disabled, redirects issued by nginx will be relative. See also server_na

nginx.org

nginx 문서를 참고해보면,

 

Syntax: client_max_body_size size;
Default: client_max_body_size 1m;
Context: http, server, location

client_max_body_size는 http, server, location위치에 지정할 수 있습니다. 즉, 개별 site-available의 conf에도 가능하고 nginx.conf에도 가능하겠습니다.

 

개별 conf에 적용해봅니다.

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    
    client_max_body_size 10M;
    
    ...

10M로 지정했습니다.

 

이제 nginx 서비스를 다시 시작하면 적용됩니다.

반응형
반응형