nginx做代理上传文件时返回HTTP 413错误码,提示信息如下:
413 Request Entity Too Large
The requested resource does not allow request data with the requested method or the amount of data provided in the request exceeds the capacity limit. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!
这是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 it exceeds the configured value, the client error 413 (Request Entity Too Large) is returned. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables client request body size checking.
可见默认情况下最大只允许上传1M的文件,把这个值调大些就可以了。一般情况下,在http下配置就可以了。但是如果你的nginx代理了多个应用,可能就要对每个应用做不同配置了,这时可以在server和location下配置。
经测试发现:upstream类型为unix socket时在location下配置client_max_body_size是无效的(tengine 1.4.2-1.5.2)。