Happy Birthday Apache!
February 23rd, 2010 Category: Linux ServerThe Apache Web Server has a reason to party, it’s 15th anniversary! Powering more than 112 million website. Congratulations!
Read more on Apache Software Foundation Blog.
The Apache Web Server has a reason to party, it’s 15th anniversary! Powering more than 112 million website. Congratulations!
Read more on Apache Software Foundation Blog.
Sometimes when changing settings in your Apache config, adding virtual hosts and so on it’s needed to reload/restart the Apache daemon. Usually this is done with:
/etc/init.d/apache2 restart
But there two big disadvantages using this method:
Indeed there is a much more better method to restart the Apache “gracefully”:
apache2ctl -t
Syntax OK
apache2ctl -k graceful
The first command will tell Apache to check your config. If everything is correct, you will get “Syntax OK”, otherwise the error will be reported but Apache will still run with the old configuration.
The second command will tell Apache to restart gracefully with the advantage that currently open connections are not aborted and the users will not be annoyed.
Avoid Double Content
There are two reasons to redirect e.g. mydomain1.de to www.mydomain1.de:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.de$ [NC]
RewriteRule ^(.*) http://www.mydomain.de/$1 [L,R=301]
The redirect is defined as 301 “permanent”. Please note that these rewrite settings only work if the correct setting for “AllowOverride” is done within the Apache settings of your host or virtual host configuration.
Redirect Domain to another Domain
If you want to redirect a complete domain, here mydomain1.de including subdomains to another domain e.g. mydomain2.de put the following code into the .htaccess of the web root directory of mydomain1.de:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)mydomain1\.de$
RewriteRule ^(.*)$ http://www.mydomain2.de/$1 [R=301,L,NC]
Using this rewrite condition all hosts *.mydomain1.de including mydomain1.de will be redirected to www.mydomain2.de. Everything behind .de/ will be kept.
Furthermore the redirect is defined as 301 which means permanent redirect. This will avoid that search machines like Goole will treat you with “double content”.
Hint
Be sure you have enabled “Options FollowSymLinks” or Options “SymLinksIfOwnerMatch” in your Apache or virtual host config. Otherwise mod rewrite will not work!
Working with Apache/2.2.3
Some further settings which worked well for a server (1GB RAM, single CPU) with max. 120 users simultaneously and doing some video streaming. Settings are found in /etc/apache2/apache.conf
Timeout 30 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 <IfModule mpm_prefork_module> StartServers 16 ServerLimit 512 MinSpareServers 16 MaxSpareServers 128 MaxClients 256 MaxRequestsPerChild 55555 </IfModule> HostnameLookups Off ServerTokens Prodme ServerSignature Off UseCanonicalName Off TraceEnable Off
HostNameLookups Off are recommended in any case.
Let’s assume your web server has high disc IO. Every access to a .PHP, .HTML, .JPG, .GIF, etc wil cause a log entry which will be stored on hard disc. In such a case it helps to disable all apache loggings.
You can check the opened log file from apache using the command:
lsof |grep apache|grep log
Oh yes, if you serve lot’s of domains on your server this list will be quite long. To disable logging just uncomment the corresponding lines e.g. in your virtual host definition:
#ErrorLog /var/log/apachd2/mydonain.de-error_log #CustomLog /var/log/apache2/mydomain.de-access_log combined
Afterwards check your apace configuration for errors:
apache2ctl -t
In case of syntax OK just restart your apache server:
apache2ctl -k graceful
This command is qute because it does a “graceful” restart without anoying users accesing your server right now.
Hint
How to check if my disc IO is high?
Use the command “vmstat 1″ and check the section “IO” (what else…). You will see bi and bo which means blocks received and blocks sent. In case the numbers are high, you will have high disc IO.
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 0 0 659476 41604 8732 347304 3 3 37 41 20 14 19 7 58 16 3 0 659476 41604 8732 347336 0 0 0 0 410 314 7 0 93 0 0 0 659476 41464 8740 347328 0 0 0 424 522 321 11 1 86 2
This article applies to apache version 2.2.3 also it will work for other versions.
Apache needs a lot of memory, this will decrease performance on a machine with e.g. 1 GByte memory and about 60 users accessing the server simultaneously a lot. There is a simply method to save memory: disable all unused modules. Yes, it really helps!
Why does it help? Because every apache process started – and a lot will be started when several users are accessing the server – will load all enabled modules.
To get an overview how much memory is consumed by the modules use the command
lsof | grep apache | grep modules
Using this command you will also see which modules consumes much memory.
In my case only the following modules are used:
Modules which are not needed are disabled using the command
a2dismod <module_name>
Useful tips regarding technical stuff for things like Linux, MySQL, apache, PHP, linux server, iPhone and more.