Make a copy of the default Apache Configuration file
$ sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bk
Edit the Configuration file
$ sudo nano /etc/apache2/apache2.conf
Changing the KeepAlive directives
Scroll down on the page until you see the below directives:
KeepAlive On: When set to ‘On’ Apache will allow persistent connections. This means more than one connection will be allowed per request. You should set this value to ‘On’ if it was set to ‘Off’ to activate KeepAlive on your server.
MaxKeepAliveRequests: This represents the maximum number of connections that should be allowed on your web server when KeepAlive is enabled.
You can set the value to ‘0’ for unlimited connections but this is not recommended. The default value is ‘100’ and this can work for most websites but you can keep this number high depending on the number of users visiting your website.
KeepAliveTimeout: This directive represents the number of seconds to wait for another request from the same client using the same connection. The default value is ‘5’ seconds.
Setting a high value on this directive may lead to a lot of idle connections and can degrade the performance of your server. So only adjust this value when users experience a lot of aborted connections when browsers try to establish connections to closed sessions.
Remember to press CTRL + X, Y and Enter to save the changes. Then, you need to restart Apache for the changes to take effect using the command below:
$ sudo systemctl restart apache2