nginx - nginx keepalive 默认值

标签 nginx

在 nginx.org 中,keepalive config 的默认值是 —,但我不太明白这是什么意思。

Syntax: keepalive connections;
Default:    —
Context:    upstream
This directive appeared in version 1.1.4.

最佳答案

为了让 Nginx 保持 TCP 连接处于事件状态,上游部分和源服务器都应配置为不完成连接。上游部分keepalive默认值意味着没有keepalive,因此连接不会被重用,每次你可以看到每个对源服务器的请求的TCP流数量增加,与keepalive发生的情况相反。您可以使用 tcpdump 进行检查。

10 Tips for 10x Application Performance博客文章很好地描述了它:

Client keepalives – Keepalive connections reduce overhead, especially when SSL/TLS is in use. For NGINX, you can increase the maximum number of keepalive_requests a client can make over a given connection from the default of 100, and you can increase the keepalive_timeout to allow the keepalive connection to stay open longer, resulting in faster subsequent requests.

Upstream keepalives – Upstream connections – connections to application servers, database servers, and so on – benefit from keepalive connections as well. For upstream connections, you can increase keepalive, the number of idle keepalive connections that remain open for each worker process. This allows for increased connection reuse, cutting down on the need to open brand new connections. For more information, refer to our blog post, HTTP Keepalive Connections and Web Performance.



另见 RFC-793 第 3.5 节:

A TCP connection may terminate in two ways: (1) the normal TCP close sequence using a FIN handshake, and (2) an "abort" in which one or more RST segments are sent and the connection state is immediately discarded. If a TCP connection is closed by the remote site, the local application MUST be informed whether it closed normally or was aborted.



两个例子,看看下面的应用数据。

没有保活:
without keepalive

使用保活:
with keepalive

关于nginx - nginx keepalive 默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46419976/

相关文章:

performance - SPDY + Nginx - 建议尽可能使用?

http - 将非 www 重定向到 https 时出错

nginx - nginx ingress 中的 body 大小到底是多少?

nginx - 我真的需要 Web 服务器和 API - 微服务架构中的网关吗

node.js - Nginx 重定向到 Node.js 后端

Nginx 未知指令 "proxy_pass"

ssl - 纯 HTTP 请求被发送到 HTTPS 端口 (NGINX)

ssl - Ubuntu/Nginx SSL 证书不工作

python - Nginx、Uwsgi、Django 问题

apache - 如何将多个域路由到多个 Node 应用程序?