我们观察到,如果我们重新加载nginx配置,则正在进行的HTTP 1.1请求会成功完成,但是没有Connection:close,这将导致客户端尝试重新使用关闭的连接。通过对两个请求进行卷曲,可以轻松地重现该行为,其中在第一个请求期间,我们通过HUP信号重新加载nginx配置。
curl -v -H "Host: foo.bar.host" "http://proxy1:4080/do-it-takes-time-and-reload-is-called" "http://proxy1:4080/do-it"
* Connected to proxy1 (xx.xxx.xxx.xxx) port 4080 (#0)
>GET /do-it-takes-time-and-reload-is-called HTTP/1.1
> Host: foo.bar.host
> User-Agent: curl/7.54.0
> Accept: */*
< HTTP/1.1 200 OK
< Server: nginx/1....
< Date: ..
< Content-Type: application/json;charset=utf-8
< Content-Length: 160
< Connection: keep-alive
< Vary: Accept-Encoding
< Keep-Alive: timeout=10, max=360
* Connection #0 to host proxy left intact
{ "foo":"bar"}
虽然这个长期存在的请求处于争用状态,但是我们执行了kill -HUP来重新加载配置,但是请注意响应如何显示Connection:keep-alive,因此curl尝试重用连接,但是服务器不需要任何连接这样请求就被拒绝了(RST)
* Found bundle for host proxy1 0x7f96e980f510 [can pipeline]
* Re-using existing connection! (#0) with host proxy1
* Connected to proxy1 (xx.xxx.xxx.xxx) port 4080 (#0)
> GET /do-it HTTP/1.1
> Host: foo.bar.host
> User-Agent: curl/7.54.0
> Accept: */*
>
* Connection died, retrying a fresh connect
* Closing connection 0
* Issue another request to this URL: ..
因此,有一种方法可以使Nginx在配置重新加载时通过Connection:close礼貌地结束对话?