HTTP upstream directives

keepalive directive (HTTP upstream)

Upstream context. Limits idle cached connections per worker, not active connections. Since 1.29.7 the documented default is 32 local; local is new in that version. Older releases require explicit enablement.

Formal Syntax & Structure

nginx syntaxnginx
keepalive connections [local];

Parameters & Attributes

NameTypeDescription
connectionsintegerIdle cached upstream connections per worker, not total connections. Modern zero disables cache.
localliteral localNew in 1.29.7; restrict cache reuse across locations. Modern default 32 local.

Working Example

Example Snippetnginx
keepalive 8;
Nginx Reference