KeepAlive Misconfiguration Exhausts Connections
warningKeepAliveTimeout set too high causes idle connections to consume worker threads/processes, reducing effective concurrency. KeepAliveTimeout set too low forces excessive TCP handshakes, increasing latency. Optimal values depend on traffic profile: APIs need 2-5s, static content 5-15s.
Monitor nginx_net_writing (connections in writing state) and nginx_backend_handled (total connections handled). If nginx_net_writing stays high relative to active requests, or if nginx_ssl_handshakes rate increases significantly, KeepAlive settings may be suboptimal. Also watch for nginx_upstream_peers_unavail indicating connection pool exhaustion.
Tune KeepAliveTimeout based on workload: use 2-5s for API endpoints with short fast requests, 5-15s for static content servers serving many small assets. Set MaxKeepAliveRequests to 100-500 for APIs, 500-1000 for static content. Monitor connection reuse rates and adjust. For TLS-heavy sites, enable session resumption to reduce handshake cost.