Nginx: check content-length before file upload takes place
I'm trying to prevent users from uploading (accidentally or maliciously) very large files to my website.
I have nginx max_client_body_size set to 4M, but if a file larger than this is uploaded, then it uploads the entir开发者_Python百科e file before returning 413 (entity too large).
I want to make nginx check the Content-Length header, so that it rejects the request before it's uploaded.
Alternatively, a Rails solution would also be acceptable.
Any help appreciated.
You may set
lingering_time 0;
# default is 30s
lingering_time sets how long nginx will read discarded body before closing connection.
精彩评论