Skip to content

Tuning Apache KeepAlive on a cPanel server

How KeepAliveTimeout, MaxKeepAliveRequests, and MPM choice interact on a cPanel Apache build, what the defaults assume, and when to tune for HTTP/2 versus legacy HTTP/1.1 clients.

Apache’s keep-alive defaults on cPanel are tuned for the prefork era — five-second timeouts to free worker slots fast. Under event MPM with HTTP/2, those defaults work against the protocol’s design: clients drop the connection mid-page-load and renegotiate, costing more time than the keep-alive saved. Tuning is small but the effect is visible in page-load metrics.

What’s happening

KeepAliveTimeout is how long Apache holds a TCP connection open waiting for the next request on it. Under prefork MPM, each open connection ties up a worker process — so short timeouts are a survival strategy. Under event MPM, idle connections are parked in an event loop with no worker cost — so longer timeouts cost nothing. HTTP/2 multiplexes streams over a single connection; the timeout governs the whole connection’s idle period, and a too-aggressive value forces the browser to reconnect mid-page.

How to verify

See the current settings:

grep -E "^KeepAlive|MaxKeepAlive" /etc/apache2/conf/httpd.conf
apachectl -V | grep MPM
curl -sI --http2 https://example.com/ | head -5
curl -v https://example.com/ 2>&1 | grep -iE "keep-alive|connection"

The first command shows the current values. The MPM tells you what range is reasonable.

The fix

  1. WHM > Apache Configuration > Global Configuration > scroll to Keep-Alive settings.
  2. For event MPM (most modern cPanel boxes):
    KeepAlive On
    KeepAliveTimeout 30
    MaxKeepAliveRequests 1000
    30 seconds matches typical browser idle behaviour. 1000 requests per connection covers any single page-load.
  3. For prefork MPM (legacy DSO):
    KeepAlive On
    KeepAliveTimeout 5
    MaxKeepAliveRequests 100
    Keep the original defaults — prefork cannot afford long idle connections.
  4. apachectl -t && apachectl graceful. The change is immediate; existing connections finish under the old setting, new connections pick up the new one.
  5. Validate with curl -v: under HTTP/1.1, the Connection: Keep-Alive header should be present and Keep-Alive: timeout=30, max=1000 should match your setting.
  6. If a CDN is in front (Cloudflare, Fastly), the keep-alive between client and CDN is governed by the CDN, not by your Apache. Your tuning still matters for the CDN-to-origin connection but the perceived effect for end users depends on the CDN’s behaviour.

For environments where keep-alive tuning is part of performance baseline, Stack Harbor sets these values during onboarding under cPanel/WHM management.