Using keep-alive connections to improve performance
Keep‑Alive connections allow a single TCP connection to handle multiple HTTP requests and responses. On ruachost.com, enabling keep‑alive improves website performance by reducing the overhead of repeatedly opening and closing connections.
Why Use Keep‑Alive?
Section titled “Why Use Keep‑Alive?”- Faster page loads: Multiple resources (CSS, JS, images) can be delivered over one connection.
- Reduced server load: Fewer TCP handshakes mean lower CPU and memory usage.
- Better user experience: Visitors see faster, smoother browsing.
- Improved performance scores: Tools like GTMetrix check for keep‑alive and penalize sites without it.
How to Enable Keep‑Alive
Section titled “How to Enable Keep‑Alive”Method 1: Using .htaccess
Section titled “Method 1: Using .htaccess”Add the following lines to your site’s .htaccess file in the root directory:
<IfModule mod_headers.c> Header set Connection keep-alive</IfModule>Save the file — keep‑alive is now enabled.
Method 2: Apache Configuration (Unmanaged VPS/Dedicated Servers)
Section titled “Method 2: Apache Configuration (Unmanaged VPS/Dedicated Servers)”Edit the Apache configuration file (httpd.conf):
KeepAlive OnMaxKeepAliveRequests 100KeepAliveTimeout 5KeepAlive On→ enables persistent connections.MaxKeepAliveRequests→ maximum number of requests per connection.KeepAliveTimeout→ time (in seconds) the server waits for the next request.
Restart Apache:
sudo systemctl restart apache2How to Verify Keep‑Alive Is Enabled
Section titled “How to Verify Keep‑Alive Is Enabled”-
Open your site in Chrome or Firefox.
-
Use Developer Tools → Network tab.
-
Inspect the response headers.
-
Look for:
Connection: Keep-Alive
Alternatively, use curl:
curl -I https://yourdomain.com