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
- WHM > Apache Configuration > Global Configuration > scroll to Keep-Alive settings.
- For event MPM (most modern cPanel boxes):
30 seconds matches typical browser idle behaviour. 1000 requests per connection covers any single page-load.KeepAlive On KeepAliveTimeout 30 MaxKeepAliveRequests 1000 - For prefork MPM (legacy DSO):
Keep the original defaults — prefork cannot afford long idle connections.KeepAlive On KeepAliveTimeout 5 MaxKeepAliveRequests 100 apachectl -t && apachectl graceful. The change is immediate; existing connections finish under the old setting, new connections pick up the new one.- Validate with
curl -v: under HTTP/1.1, theConnection: Keep-Aliveheader should be present andKeep-Alive: timeout=30, max=1000should match your setting. - 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.