An article in the category of 'notes in the margins'.
TL:DR:
http2_max_field_size 8k; # will save everyone!On one of the projects, after changing some internal backend logic, I started noticing a strange response_code in the logs, namely — 0. In the logs, it looks something like this:
{
"timestamp": "2020-01-17T08:41:51+00:00",
"remote_addr": "zzz.zzz.zzz.zzz",
"request_time": 0,
"upstream_response_time": "",
"upstream_header_time": "",
"http_accept_language": "-language",
"response_status": 0,
"request": "",
"host": "example.com",
"upstream_addr": "",
"http_referrer": "",
"request_length": 5854,
"bytes_sent": 0,
"http_user_agent": ""
}
Reading the documentation and googling on this topic yielded exactly nothing — since it’s claimed that this behavior occurs when the client closes the connection without sending headers. And various exotic scenarios with buffer size for wsgi_ that didn’t fit our case at all.
Overall, we decided that the problem was not a problem, considering that at our scale, it was completely uncritical.
Right until I was puzzled by the next issue: in some cases, links open perfectly via http, but completely refuse to work over https, giving a wonderful: Connection #0 to host example.com left intact
curl: (52) Empty reply from server
In the logs, I could only track this by IP — no request or any other data, as seen from the example above — is available. Just the notorious status 0, but I know that I didn't interrupt the request! I started digging into what could be going wrong. And it turned out to be very simple:
listen 443 ssl http2 backlog=8192;
So here’s the thing — if you use http2 for ssl connections, it’s not enough just to configure the request buffers, you need to configure them in ngx_http_v2_module as well, namely:
Syntax: http2_max_field_size size;
Default: http2_max_field_size 4k;
Context: http, server
Limits the maximum size of the request header compressed with HPACK. The limit applies equally to both the name and the value. If Huffman encoding is applied, the actual size of the unpacked name and value strings may be larger. The default limit works for most requests.
In general, that’s it. And why is that? Because the length of the link was large — more than those 4k.
Setting it to, say, 8kb (or as much as you’re sure will be enough) solves the problem.
That's the way it is.
Source: habr.com
