Dec 02, 2025
Domantas G.
5min Read
Enabling Keep-Alive can help to optimize website’s performance and deliver a better user experience. It allows a visitor’s browser to reuse a single TCP connection to load page content.
Keep-Alive is usually enabled by default on your origin server. But if this header is disabled, there are a few solutions to turn it on yourself.
This tutorial will show you the steps to enable Keep-Alive and files to prepare beforehand. It will also go over the reasons why you should activate Keep-Alive.

Keep-Alive, also known as a persistent connection, is a communication pattern between a server and a client to reduce the HTTP request amount and speed up a web page.
When Keep-Alive is turned on, the client and the server agree to keep the connection for subsequent requests or responses open.
By default, HTTP connections close at the end of data transactions. This means that clients create a new connection to request each file of a page and servers close these TCP connections after sending the data.
However, if a server needs to respond to multiple HTTP requests simultaneously and serve a single file for each new TCP connection, the site page’s load time will be increased. This can lead to a poor user experience.
To overcome this issue, website owners need to enable the Keep-Alive header to limit the number of new connections.
By turning the Keep-Alive connection header on, clients can download all the content such as JavaScript, CSS, images, and videos through a single TCP connection instead of sending a different request for each file.
Here’s a picture to demonstrate how Keep-Alive works:

Keep-Alive can improve website speed and performance as it maintains an open connection between a client and a server, saving the time needed to serve files.
Enabling Keep-Alive has additional benefits, such as:
The file you need to prepare before enabling the HTTP Keep-Alive header depends on what server you use and your access privileges.
Make sure that you have access to one of the following files before continuing this guide:
When you’re finished, follow these steps to enable Keep-Alive:
Although many hosting providers have Keep-Alive enabled by default, some of them might have this header disabled for performance reasons.
To check whether Keep-Alive is enabled on your server, run a website speed test using a tool such as GTMetrix.

Hostinger users can also use the page speed test feature on hPanel to check if Keep-Alive is working properly. You can access it by opening the hPanel dashboard and then going to the Performance → Page Speed section.
Choose the website you want to test and the type of device. Click Analyze, then wait until the process is complete. If Keep-Alive is working properly, you should see a good score.
If the analysis tool shows that Keep-Alive is disabled, move to the next step.
To enable Keep-Alive, you need to explicitly request it via the HTTP header by accessing .htaccess or the main configuration file of your web server. If you turn on Keep-Alive, the HTTP response header will show Connection: keep-alive.
The following tutorial will cover four different methods to enable Keep-Alive on your server.
Enable Keep-Alive and override any server settings by adding the following code to your .htaccess file:
<ifModule mod_headers.c> Header set Connection keep-alive </ifModule>
This method should work on most Linux-based shared hosting providers. If you use Hostinger, locate the .htaccess file using the File Manager.
To do that, open the hPanel dashboard, then click the File Manager button. You can find the .htaccess file under the public_html folder. Right-click on the file, then choose edit to add the code.
Make sure to test your website for any errors after editing the .htaccess file.
If you have access to the Apache configuration file, it’s possible to enable the extension from there.
To locate the httpd.conf file, enter the following command into the command line:
find / -name httpd.conf
The following parameters affect Keep-Alive functionality in Apache, from enabling the persistent connection to defining the idle connection timeout:
KeepAlive On to enable the extension or KeepAlive Off to disable it.Here is what the configuration should look like:
# # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 50 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. # KeepAliveTimeout 10
As a web server and reverse proxy, NGINX has Keep-Alive enabled by default. In some cases, however, it may be disabled. Users can enable it using ngx_http_core_module.
Look for the value keepalive_disable – in most cases, this will be the reason why Keep-Alive is not working.
Before deleting the value to enable Keep-Alive, make sure to find out why it was disabled in the first place.
If you use a Windows-based server, enable the Keep-Alive extension through the command line.
The following command will enable it:
appcmd set config /section:httpProtocol /allowKeepAlive:true
If you wish to disable Keep-Alive, use:
appcmd set config /section:httpProtocol /allowKeepAlive:false
Windows Server users can also enable the Keep-Alive header by editing the configuration files directly or writing WMI scripts.
Once Keep-Alive is enabled, run another scan with GTMetrix or KeyCDN’s HTTP Header Checker to see whether the extension is active.
It’s also possible to check the HTTP header via the terminal using the following command:
curl -I http://example.com/example.php
In the following example, we’ll check the HTTP header of hostinger.com:
curl -i http://hostinger.com/index.php
This gives us the following results:
HTTP/1.1 301 Moved Permanently Date: Tue, 27 Jul 2021 01:55:24 GMT Transfer-Encoding: chunked Connection: keep-alive Cache-Control: max-age=3600 Expires: Tue, 27 Jul 2021 02:55:24 GMT Location: /index.php
The Connection: keep-alive part shows that Keep-Alive is functional.

Enabling Keep-Alive is a great way to optimize your website as it helps improve speed and performance, ensuring faster load times and higher efficiency.
By turning the Keep-Alive header on, the client and server can reuse a single TCP connection for a number of requests and responses. This eliminates the need to establish new connections for each HTTP request or response.
Let’s recap the steps to enable the Keep-Alive header:
We hope this article has helped you enable Keep-Alive. If you have any questions, let us know in the comment section below.
How to Leverage Browser Cache
What Is Website Caching and How to Clear It
How to Minify CSS, HTML and JavaScript
How to Enable GZIP Compression
How to Run a GTmetrix Speed Test
Comments
October 29 2018
Thank you for the terrific article! My site went from 5-8 seconds down to 0-2 fully loaded. I did have an issue where adding the code to .htaccess didn't work but found a fix by installing 'Litespead Cache', editing my wp-config.php and then adding the code through admin dashboard.
November 06 2018
That's awesome, May! Sounds like a really huge website speed improvement, nicely done ;)