http1.0 vs http1.1
Connection: keep-alive
Connection: close
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 11 Aug 2016 15:23:13 GMT
Keep-Alive: timeout=5, max=1000
Last-Modified: Mon, 25 Jul 2016 04:32:39 GMT
Server: Apache
so_keepalive
SO_KEEPALIVE
Linux has built-in support for keepalive. You need to enable TCP/IP networking in order to use it. You also need procfs support and sysctl support to be able to configure the kernel parameters at runtime.
The procedures involving keepalive use three user-driven variables:
tcp_keepalive_time
the interval between the last data packet sent (simple ACKs are not considered data) and the first keepalive probe; after the connection is marked to need keepalive, this counter is not used any further
tcp_keepalive_intvl
the interval between subsequential keepalive probes, regardless of what the connection has exchanged in the meantime
tcp_keepalive_probes
the number of unacknowledged probes to send before considering the connection dead and notifying the application layer
sysctl -a | grep tcp.keep
net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_time = 7200
nginx 相关配置
## Module ngx_http_core_module
keepalive_disable
keepalive_requests
keepalive_time
keepalive_timeout
listen so_keepalive=30m::10
## Module ngx_http_upstream_module
keepalive
keepalive_requests
keepalive_time
keepalive_timeout
## Module ngx_http_proxy_module
proxy_socket_keepalive