We have few requests that takes http headers size more than the default accepted size in our tomcat application i.e., maxHttpHeaderSize = 8192 (https://tomcat.apache.org/tomcat-8.0-doc/config/http.html)
And also nginx, has a default limit for buffers that can be allocated for large client requests i.e., large_client_header_buffers size = 8K (http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers)
However, without increasing the large_client_header_buffers on nginx side, requests can still go through if just maxHttpHeaderSize parameter in tomcat is increased.
As per nginx documentation, "Buffers are allocated only on demand." I do not understand this. Are buffers not allocated for every request?
nginx request buffers consist of two parts:
The documentation for
client_header_buffer_size
explains nginx strategy:For
large_client_header_buffers
documentation states the following:So, by default, nginx allocates 1k of memory for request headers. If request headers do not fit into this space, nginx allocates up to N blocks of size X to store the additional request headers.
N
andX
are specified inlarge_client_header_buffers
directive.For example, if there are 4 kB of request headers, nginx will use the 1kB base allocation and then allocate one 8 kB block for the rest.
With the default values, total size for headers can be 1 kB + 4 * 8 kB = 33 kB. However, because each request header line has to fit completely into the buffer, the buffer cannot be fully used. So the actual capacity for headers is less.
I don't know how Tomcat header limits work, but I assume that its strategy is different from nginx strategy and the values are not directly comparable.
nginx default values are:
which means it can process up to 4 requests of up to 8kB size in parallel. it's seems to be that your bottleneck is tomcat, which has fixed 4kB parameter for header size value, so up to 4 parallel requests larger than 1kB and smaller than 8kB can pass through your nginx, but they will stuck on tomcat if his parameters are unchanged.