How to Enable Keep Alive in Apache

enable keep alive in apache

Keep Alive is a useful feature that allows you to maintain persistent TCP connections between web server and web browser, for HTTP requests. This speeds up your website by avoiding the creation of new connections for each request. Here’s how to enable Keep alive in Apache web server.


How to Enable Keep alive in Apache

To enable keep alive, you need to enable the “Connection: Keep-Alive” HTTP header. Here are the steps to enable Keep alive in Apache.


There are two ways to enable Keep alive in Apache – using .htaccess and using config file. Let’s look at the both the methods below


1. Using .htaccess file

.htaccess file allows you to configure Apache web server without accessing its config file. Before proceeding further, please ensure you have enabled .htaccess file for your Apache web server. Here are the steps to do it:


Open .htaccess file in a text editor and add the following lines to it

<ifModule mod_headers.c>
  Header set Connection keep-alive


This will add keep alive headers to your requests and override most web server limitations.



2. Using Apache Config file

If you are able to access Apache config file, you can directly enable keep alive in apache by adding the following directives to your config file

KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 100


  • KeepAlive – Main directive to enable keep alive
  • MaxKeepAliveRequests – Max number of persistent connections to be allowed. Setting it to 0 means unlimited requests
  • KeepAliveTimeout – No. of seconds to wait for the next request on same connection


Restart Apache Server

Restart Apache web server to apply changes


/etc/init.d/httpd restart 



sudo /etc/init.d/apache2 restart 


That’s it! Keep Alive headers will be enabled for Apache web server

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!