HTTP keep-alive lets a client send several requests over one TCP connection instead of opening a new connection for each one. In HTTP/1.1 it is on by default, so for most servers "enabling" it means tuning timeouts and request limits, not flipping a switch. If you want to see which headers your server actually returns, the free Pingfloat tools let you inspect HTTP response headers with no installation or account.
This guide covers what the headers mean, where keep-alive no longer applies (HTTP/2 and HTTP/3), the settings worth changing on common servers, and how to troubleshoot connections that refuse to be reused.
TL;DR
- Keep-alive, also called a persistent connection, reuses one transport connection for many request-response exchanges, which saves the cost of repeated connection setup.
- HTTP/1.1 connections persist by default unless someone sends
Connection: close. You only needConnection: keep-alivefor old HTTP/1.0 behavior. Keep-Alive: timeout=5, max=1000is an optional hint.ConnectionandKeep-Aliveare connection-specific headers and are not allowed in HTTP/2 or HTTP/3.- Real control lives in server settings: idle timeout and maximum requests per connection.
- When reuse fails, look first for unread response bodies, proxies in the path, and idle timeouts that close the connection before your next request.
Table of Contents
- What HTTP keep-alive actually does
- Connection: keep-alive vs the Keep-Alive header
- Keep-alive in HTTP/2 and HTTP/3
- HTTP keep-alive is not TCP keepalive or a heartbeat
- How to enable and tune keep-alive
- Proxies, load balancers and hop-by-hop behavior
- Checking and troubleshooting connection reuse
- Where Pingfloat fits in
- Our perspective
- FAQ
- Sources
What HTTP keep-alive actually does
Without persistence, every request would need its own TCP connection, and for HTTPS its own TLS handshake on top. MDN's connection management guide describes persistent connections as connections that stay open so successive requests reuse them, which cuts the time spent opening new ones.
Think of a page that loads an HTML document, a stylesheet, a script and six images. With persistence, the browser can send those requests over a small number of open connections. Without it, it pays the handshake cost eight or more times. The saving is largest on high-latency links, on TLS connections, and for API clients that make many small calls to the same host.
There is a condition. RFC 9112, the HTTP/1.1 specification, requires that each message define its own length so the receiver knows where one ends and the next begins. A server must read the whole request body or close the connection, and a client that wants to reuse a connection must read the whole response body. That one rule explains most real-world reuse bugs, which we come back to below.

Connection: keep-alive vs the Keep-Alive header
These two headers are often confused.
| Header | Role | Example |
|---|---|---|
Connection: keep-alive | Asks to keep the connection open after this exchange | Connection: keep-alive |
Connection: close | Asks to close after the current transaction | Connection: close |
Keep-Alive | Optional hint with parameters | Keep-Alive: timeout=5, max=1000 |
MDN's Connection reference says close signals the end of the transaction and that persistence is the HTTP/1.1 default. The explicit keep-alive value is mainly useful for negotiating the historical HTTP/1.0 behavior. RFC 9112 says HTTP/1.0 connections close after a response unless the recipient chooses to honor that old mechanism.
The Keep-Alive header adds parameters. Per MDN's Keep-Alive reference, timeout is an idle time in seconds. The host may keep the connection longer, but should try to keep it at least that long. The header only has effect alongside Connection: keep-alive.
Two practical consequences:
- Seeing
Connection: keep-alivein a response does not prove anything special is configured. On HTTP/1.1 it is mostly a courtesy. - Seeing
Connection: closeis the signal that deserves attention: the peer is ending persistence for this exchange.
Keep-alive in HTTP/2 and HTTP/3
HTTP/2 and HTTP/3 changed the model. Both multiplex many requests as streams over one connection, so persistence is built in rather than negotiated. HTTP/3 runs over QUIC, and RFC 9114 says it does not use the Connection header to signal connection-specific fields.

MDN states that Connection and Keep-Alive are prohibited in HTTP/2 and HTTP/3. Its compatibility notes add that Chrome and Firefox ignore them in HTTP/2 responses, while Safari follows the specification and will not load a response that contains them. So if you add these headers by hand in an app or proxy config, a response that works in one browser can fail in another.
Idle handling also differs. In HTTP/3, each QUIC endpoint declares an idle timeout during the handshake. RFC 9114 says that after the idle interval, implementations must use a new connection for later requests, and should do so when the timeout is near. For a deeper comparison, see our guide to HTTP/2 vs HTTP/3.
HTTP keep-alive is not TCP keepalive or a heartbeat
Three things share the word "keepalive" and solve different problems:
- HTTP keep-alive decides whether the next HTTP request may reuse an open connection. It lives at the HTTP layer and has no probing of its own.
- TCP keepalive is an operating-system socket option that sends small probe packets on an idle connection to detect a dead peer. It does not make HTTP reuse a connection.
- Application heartbeats (a ping message over a WebSocket, a periodic health call) are your own code checking that the other side is alive.
So setting a long TCP keepalive will not stop a server from closing an idle HTTP connection after five seconds, and a long HTTP idle timeout will not detect a peer that vanished. If a load balancer silently drops idle connections, the fix is usually to make your client's idle timeout shorter than the balancer's, not to add probes.
How to enable and tune keep-alive
On HTTP/1.1 servers it is already on. What you tune is how long an idle connection survives and how many requests one connection may serve. RFC 9112 notes that servers and proxies commonly impose idle timeouts but sets no required length, so defaults differ by software.
nginx
The nginx core module documentation lists keepalive_timeout (how long an idle client connection stays open) and keepalive_requests (the maximum requests per connection). Setting keepalive_timeout 0 disables persistence for clients. For connections from nginx to your backend, persistence needs an upstream block with a keepalive directive, proxy_http_version 1.1 and an empty Connection header:
upstream app {
server 127.0.0.1:8080;
keepalive 32;
}
server {
location / {
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
Without those last two lines, nginx talks HTTP/1.0 to the backend and closes the connection after each request.
Apache HTTP Server
Apache's core module reference documents KeepAlive (on or off), KeepAliveTimeout (how long to wait for the next request) and MaxKeepAliveRequests. A long KeepAliveTimeout helps clients but holds a worker busy while it waits, so on a busy server keep it short.
Application frameworks and clients
Framework defaults vary. As one example, Apache Pekko HTTP 2.0 defaults its server idle timeout to 60 seconds, its request timeout to 20 seconds and max connections to 1024, with a 60 second client idle timeout. Its reference also advises keeping the request timeout shorter than the idle timeout so the idle timeout does not reset the connection first. The same principle applies elsewhere: know both numbers and keep them consistent along the path.
A sensible tuning order
- Confirm the protocol. If clients negotiate HTTP/2 or HTTP/3, stop adding connection headers.
- Set the server idle timeout to a few seconds up to about a minute, depending on how bursty your clients are.
- Set a request cap per connection high enough not to churn connections, low enough that long-lived connections get recycled and release memory.
- Make sure each hop behind the first, such as proxy to app server, has persistence configured too.
- Align timeouts so the side that closes idle connections is the side that expects to.
Proxies, load balancers and hop-by-hop behavior
MDN stresses that connection management in HTTP/1.x, including Connection and Keep-Alive, is hop-by-hop. A browser may keep a connection to your CDN alive while the CDN opens a fresh connection to your origin for every request, or the reverse. Checking headers at the edge tells you about the edge link only.
That is why using HTTPS everywhere matters for reuse too: TLS terminated at a proxy means two separate connections with their own timeouts, and each one needs sensible persistence settings.
If latency looks wrong between hops, a traceroute shows where time is spent along the path, which helps separate slow networks from slow connection setup.
Checking and troubleshooting connection reuse
Look at the headers
Request a page and read the response headers. A Connection: close on an HTTP/1.1 response means the server is ending persistence. Our guide on debugging HTTP/2 and HTTP/3 headers shows how to read them without installing anything. For HTTP/2 and HTTP/3, remember that missing keep-alive headers are correct, not a fault.
Read the response body to the end
The Go team's October 2026 post, Better HTTP/1 connection reuse, explains that in HTTP/1 an unread response body prevents reuse, because the next response cannot be located until the current one is consumed. If your client opens a new connection per request despite a keep-alive server, check that you read and close every body, including error responses and redirects you ignore. The same post notes that HTTP/2 multiplexing means an unread body on one stream does not block other requests the same way.
Expect connections to close
RFC 9112 lets either endpoint or a proxy close a connection at any time. A robust client handles a closed connection between requests and only automatically retries idempotent requests (ones safe to repeat, such as GET). Retrying a POST blindly after a dropped connection can duplicate an order or a payment.
Common symptoms
| Symptom | Likely cause | What to check |
|---|---|---|
| New TCP/TLS handshake on every request | Connection: close, HTTP/1.0 upstream, unread bodies | Response headers, proxy config, client code |
| Occasional "connection reset" on the first request after a pause | Server closed idle connection just as client reused it | Align idle timeouts, retry idempotent calls |
| Page works in Chrome, fails in Safari | Connection header sent over HTTP/2 | Remove hop-by-hop headers from app and proxy config |
| Many open connections, high memory | Timeout too long or no request cap | Lower idle timeout, set a request limit |
Watch for the side effects
A connection that is reused quietly depends on a healthy server. If workers are saturated waiting on idle connections, users see slow pages or errors that a simple ping will not reveal. Uptime checks from outside catch that class of problem, and cached responses interact with it too, so it is worth reviewing Cache-Control headers alongside your connection settings. For status codes returned when a connection or upstream fails, see the HTTP status codes reference.
Where Pingfloat fits in
Keep-alive tuning is only worth doing if you can see the result. Pingfloat's Website Uptime Monitor checks that your site stays reachable after you change timeouts or proxy settings, and the rest of the suite covers the checks that sit around it: HTTP response headers, SSL certificates and traceroute. Core tools are free and need no installation or account. Sign-up adds options such as scheduled uptime monitoring and saved results.

Teams that want to wire these checks into their own scripts can use the Pingfloat Public API.
Our perspective
Most keep-alive problems we would expect a developer to hit are not about a missing header. They come from two systems that disagree about how long an idle connection lives, or from an HTTP/1.1 hop that quietly became HTTP/1.0.
That is why we build Pingfloat around quick, readable checks. You should be able to look at response headers, confirm a certificate, trace a path and watch uptime in the same place, with no install and no account for the core tools. When you change a timeout, the next question is always "did anything get worse?", and a fast, free answer beats a guess.
Our advice: keep the config boring. Leave HTTP/1.1 persistence on, set one idle timeout you can explain, align it across each hop, and monitor the result.
Andreas
FAQ
Is HTTP keep-alive enabled by default?
Yes for HTTP/1.1. RFC 9112 says connections persist unless Connection: close is sent. HTTP/1.0 closes after each response unless both sides use the older keep-alive mechanism. HTTP/2 and HTTP/3 reuse a single connection by design.
Should I send Connection: keep-alive?
On HTTP/1.1 it is not needed, since persistence is already the default. It matters mainly for HTTP/1.0 clients and servers. Do not send it over HTTP/2 or HTTP/3, where it is prohibited and Safari may refuse the response.
What does the Keep-Alive timeout value mean?
It is a hint, in seconds, for how long the sender will keep an idle connection open. The peer may hold it longer but should try to keep it at least that long. It has effect only with Connection: keep-alive.
Why does my client still open a new connection for every request?
The usual causes are an unread response body, a Connection: close header, an HTTP/1.0 hop between proxy and backend, or a server idle timeout that is shorter than the gap between your requests. Check the response headers first, then your client code.
Sources
- Connection management in HTTP/1.x, MDN
- RFC 9112: HTTP/1.1
- Connection header, MDN
- Keep-Alive header, MDN
- RFC 9114: HTTP/3
- Better HTTP/1 connection reuse, The Go Programming Language
- nginx ngx_http_core_module
- Apache HTTP Server 2.4 core module
- Apache Pekko HTTP configuration
