HTTP keep-alive, also called a persistent connection, lets a client send several requests over the same TCP (and TLS) connection instead of opening a new one per request. In HTTP/1.1 connections are persistent by default unless a side sends Connection: close.
Why it matters
Each new connection costs a TCP handshake and, for HTTPS, a TLS handshake, adding at least one or two round trips before any data flows. Reusing connections removes that cost for every page asset. Servers also set an idle timeout, because open idle connections consume memory and worker slots.
Example
HTTP/1.1 200 OK
Connection: keep-alive
Keep-Alive: timeout=5, max=100
Relevant defaults, as of current docs: nginx keepalive_timeout is 75s and Apache KeepAliveTimeout is 5s; verify against your version. To reuse connections from nginx to an upstream:
upstream app { server 127.0.0.1:3000; keepalive 32; }
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://app;
}
Common mistakes
- Setting a proxy's idle timeout longer than the backend's, so the proxy reuses a connection the backend already closed, causing sporadic 502 errors.
- Setting very long timeouts on a busy server and exhausting worker slots.
- Forgetting
proxy_http_version 1.1and the emptyConnectionheader, which disables upstream reuse in nginx. - Expecting the
Keep-Aliveheader in HTTP/2, which does not use it.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.