艾克斯记事

Nginx “Request entity too large” 413错误

  发生错误的愿意是Nginx判断客户端发送的HTTP数据流过大,绝大多数是发生在上传文件时候,上传的文件大小超过了Nginx设置的报文大小限制所产生的错误,解决办法也很简单就是讲报文大小配置的大一些,根据实际需要进行设置,例如我是在给一个私有云配置的时候文件大小设置为2GB,用来保障大多数文件都是可上传的。

解决办法

  在Nginx配置文件中添下面这行代码,来配置Nginx上传文件的大小限制,可以将其添加到http{}server{}location{},不同位置生效范围不一致,建议配置在server{}中。

client_max_body_size 200m;

这里引用一部分Nginx官方对于此项配置的说明,您也可以前往Ningx官网文档查看更多的内容:

http://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, specified in the “Content-Length” request header field. 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.