Skip to content

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.

  • 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.

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 On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
  • KeepAlive 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 apache2
  1. Open your site in Chrome or Firefox.

  2. Use Developer Tools → Network tab.

  3. Inspect the response headers.

  4. Look for:

    Connection: Keep-Alive

Alternatively, use curl:

curl -I https://yourdomain.com