连接将在 Http/2 中保持多长时间?
我了解 Http/2 每个域使用一个连接并进行多路复用。但我没有得到有关连接将保持多长时间的任何信息。
最佳答案
与 HTTP/1.1 一样,连接在 HTTP/2 中保持事件的时间取决于客户端和服务器的实现。 HTTP/2 specification说
HTTP/2 connections are persistent. For best performance, it is expected that clients will not close connections until it is determined that no further communication with a server is necessary (for example, when a user navigates away from a particular web page) or until the server closes the connection.
[...]
Servers are encouraged to maintain open connections for as long as possible but are permitted to terminate idle connections if necessary. When either endpoint chooses to close the transport-layer TCP connection, the terminating endpoint SHOULD first send a GOAWAY (Section 6.8) frame so that both endpoints can reliably determine whether previously sent frames have been processed and gracefully complete or terminate any necessary remaining tasks.
因此,两个端点都可以通过发送
GOAWAY
优雅地关闭连接。框架。 Nginx和 Apache让您配置一个超时,然后关闭空闲的 HTTP/2 连接。 nginx 的默认值为 3 分钟,Apache 的默认值为 5 秒。
关于http - 连接将在 Http/2 中保持多长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53803772/