MaxKeepAliveRequests
MaxKeepAliveRequests
is the maximum number of requests to serve on a TCP connection. It limits the number of requests allowed per connection. If it is set to 0
, unlimited requests will be allowed. You can set it to any value you desire.
Keep this setting to a high value for maximum server performance. The recommended value ofMaxKeepAliveRequests
is 500
.
To change this setting, edit the Apache configuration file:
sudo nano /etc/httpd/conf/httpd.conf
Add the following line:
MaxKeepAliveRequests 500
KeepAliveTimeout
KeepAliveTimeout
defines the number of seconds Apache will wait for the new request from connected clients before closing the connection. (Once the server receives a request, the Timeout directive applies instead.)
By default Keepalive
is disabled in CentOS 7. If Keepalive
is set to on
, it is a good idea to set theKeepAliveTimeout
value low.
The recommended KeepAliveTimeout
can be between 1
to 5
.
You can do this by editing Apache configuration file:
sudo nano /etc/httpd/conf/httpd.conf
Add the following line:
KeepAliveTimeout 5
KeepAlive
KeepAlive
sets whether the server allows more than one request per connection. It can be used to prevent any one client from consuming too much of the server's resources.
By default KeepAlive
is disabled in CentOS 7. Once the Apache server is getting requests from hundreds and thousands of IPs at once, this setting should be On
.
You can enable this setting by editing Apache configuration file:
sudo nano /etc/httpd/conf/httpd.conf
Add the following line:
KeepAlive On
Configure MPM Prefork
One reason for poor Apache performance is that Apache is having trouble coping with the load. The Apache MPM (Multi-Processing Module) can help.
mpm_prefork_module
is included and enabled in the default Apache installation on CentOS 7. To confirm this run the following command:
sudo apachectl -t -D DUMP_MODULES |grep mpm
You should see mpm_prefork_module (shared)
if mod_deflate
is installed and enabled.
You can make Apache performance better using the Apache MPM prefork module. To do this, set the following parameters in your Apache configuration file:
sudo nano /etc/httpd/conf/httpd.conf
Add the following lines:
KeepAlive Off
<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 3000
</IfModule>
Save and close the file, then restart Apache to reflect these changes.
sudo apachectl restart
AllowOverride
If AllowOverride is set to 'All', then Apache will attempt to open a .htaccess
file in each directory that it visits.
For example:
DocumentRoot /vaw/www/html/website1
<Directory />
AllowOverride All
</Directory>
If a request is made for URI /index.html
, then Apache will attempt to open .htaccess
file in /
, /var/
,/var/www/
, /var/www/html/
and /var/www/html/website1/
.
Therefore, it is good idea to add AllowOverride all
for a specific directory only:
DocumentRoot /vaw/www/html/example
<Directory /var/wwww/html/example/admin>
AllowOverride All
</Directory>
DNS Lookups
The biggest reason for Apache web server slowdowns is the time required to perform DNS lookups. Apache will record the full host name of each incoming client connection in its access.log
file. Resolving each one eats up a significant chunk of time.
The HostnameLookups
option enables DNS lookup so that hostnames can be logged instead of the IP address. By default HostnameLookups
is Off
in Apache.
You can verify that this is the case by editing the Apache config file:
sudo nano /etc/httpd/conf/httpd.conf
Be sure the HostnameLookups line reads:
HostnameLookups Off
Save and close the file when you are finished, then restart Apache to reflect changes.
sudo apachectl restart