How to Enable Keep-Alive for Apache Servers

How does Keep-Alive work?

Every time a visitor requests a file from your server, there is communication between the visitor's browser and your server. Because the network connection remains open (alive) when Keep-Alive is enabled, the server only needs to authorize the request once rather than several times, which significantly reduces CPU utilization and network overhead.

Keep-Alive is typically enabled by default on web servers. It's not always the case, though. For reasons related to server speed (their servers, not your website), some hosting firms disable keep-alive. To check the keep-alive status of your domain, use a website speed tester or a keep-alive checker.

How to Enable Keep-Alive for Apache Servers

Whether you run a Drupal, WordPress, Joomla, or any other sort of CMS website, there are several methods you may enable Keep-Alive for Apache. The simplest approach to enable HTTP Keep-Alive connections is through altering the .htaccess file, but you can also do it using server-side access (you need access to your server or droplet for this). You can find the .htaccess method below.

Edit the .htaccess File

To enable Keep-Alive through .htaccess, you need to add the following code to your .htaccess file:




The benefit of employing this method is that it overrides any modifications made to your server's configuration file. Therefore, you can enable it without requiring server-side access. After making changes to the .htaccess file, always test your website for bugs or malfunctions to avoid mistakes or situations where it doesn't work out as you want it to (in which case you should not use this method). Keep the updated settings if they work. Remove the lines from the .htaccess file if it doesn't.

Adjust Apache Settings

Every time you install Apache from scratch, Keep-Alive should be configured automatically on a Unix (Linux) server. If it isn't already enabled, it is simple to do so by making the following changes to the httpd.conf configuration file for Apache:

  • KeepAlive: Set it to "KeepAlive on" to enable Keep-Alive. To disable it, use "KeepAlive off".
  • MaxKeepAliveRequests: Sets the maximum number of requests for every keep-alive connection. A good number to start with is 60 requests per connection.
  • KeepAliveTimeout: Sets how long your server should wait for new requests from clients. The 15-second default is too high. Set it to 3 seconds to start with and gradually go up when it underperforms. Setting it to a lower amount of seconds results in fewer parallel connections, which again results in less server load.

Conclusion

There is no downside to enabling HTTP Keep-Alive when it comes to improving your website speed. Using a Keep-Alive connection will almost always speed up your website.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Do Website Transfers Affect SEO?

It's a well-known fact that Search Engine Optimization (SEO) is crucial for increasing the...

How to Change the PHP Timezone for Your Website

In some circumstances, you might need to modify your PHP setup in a specific way. One of these...

How to Change the Max Memory and Max Upload Limit

There are certain scenarios when you may be asked to make changes to your PHP configuration....

Why is phpinfo() Disabled and How to Enable It

Disabling the PHP function phpinfo() has a good reason behind it — security. The phpinfo()...

How to Make All .html Pages to Run as .php Files Using .htaccess

PHP can be extremely useful when used in conjunction with HTML to enhance the features of a...