Reading large request body using ngx_http_read_client_request_body

NginxNewbee nginx-forum at
Sat May 18 21:10:29 UTC 2019

Apologies if this is a trivial question. I have searched it on web and none
of the answers have solved my problem. I am trying to read request body and
thing seem to work fine if request body is small (4  kb). As soon as it
becomes 4+ megabytes,ngx_http_read_client_request_body returns NGX_AGAIN
(-2) in rc and my RequestBodyHandler is never called. 

snippet of nginx.conf is like this for buffer settings. I have removed lot
of other stuff from nginx.conf to keep it brief.

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

	client_body_buffer_size 1m;
	client_max_body_size 0;

/ * code sample start */
 r->request_body_in_single_buf = 1;
 r->request_body_in_persistent_file = 1;
 r->request_body_in_clean_file = 1;
 r->request_body_file_log_level = 0;

        rc = ngx_http_read_client_request_body(r, RequestBodyHandler);

		CORE_TRACE(Error, L"Nginx read request error: %d", rc);
                return from thread.                

        return NGX_DONE.

/ * code sample end */

Just to add some more context here. I use nginx thread pool. So my module's
content handler basically queues a task to thread pool. Callback of thread
eventually calls ngx_http_read_client_request_body to read request body. If
there is an error (as stated in above if condition), thread simply returns
and the completion handler of thread is called by nginx. In the completion
handler, I do finalize request with NGX_DONE always.

Posted at Nginx Forum:,284214,284214#msg-284214

More information about the nginx mailing list