Website Traffic Statistics for Multiple virtual Hosts

This article of mine is dedicated towards the log processing for multiple virtual hosts (Name Based Sites). As we know almost every hosting server is having at least one hosting control panel installed on it, to control hosting services. Which will make all the jobs easy for maintaining each site on the server, including the per site based logging. But what if there is no control panel on the server and site owner is demanding for individual traffic statistics of its site.
There are different ways of doing that, but simplest one is configuring webalizer for multiple virtual hos. Let us design a simple scenario to proceed:
Assume that we have some virtual hosts (Name based sites)
1. alpha.secaudi.com with server access log file /var/log/httpd/access_log_alpha
2. beta.secaudi.com with server access log file /var/log/httpd/access_log_beta
3. gama.secaudi.com with server access log file /var/log/httpd/access_log_gama
and required is the individual traffic statistics for all these sites.
Create a centralized folder for webalizer configuration
# mkdir /etc/webalizer
Create individual webalizer configuration files for each site using sample configuration file
# cp /etc/webalizer.conf /etc/webalizer/alpha.secaudi.com.conf
# cp /etc/webalizer.conf /etc/webalizer/beta.secaudi.com.conf
# cp /etc/webalizer.conf /etc/webalizer/gama.secaudi.com.conf
Now create individual directories for usage for each site
# mkdir -p /var/www/usage/{alpha,beta,gama}
Modify individual webalizer configuration file for each site, for example: alpha.secaudi.com.conf
LogFile /var/log/httpd/access_log_alpha
OutputDir /var/www/usage/alpha
HostName alpha.secaudi.com
Similarly modify files for the other sites.
Run the following command to process webalizer statistics for each site
# webalizer -c alpha.secaudi.com
# webalizer -c beta.secaudi.com
# webalizer -c gama.secaudi.com
Required output will be in
/var/www/usage/alpha for alpha.secaudi.com
/var/www/usage/beta for beta.secaudi.com
/var/www/usage/gama for gama.secaudi.com
You can simplify this task if you are having large number of sites on your server
Write a small script named webstats.sh
# vi webstats.sh
for x in /etc/webalizer/*.conf
do
webalizer -c $x
done
required you should have configured webalizer configuration file for each virtual host.
Now you have to provide the URL to website owner by making soft link of usage directory in the DocumentRoot of that particular site.
For example: For alpha.secaudi.com, DocumentRoot is /var/www/html/aplha.secaudi.com
# ln -s /var/www/usage/alpha /var/www/html/aplha.secaudi.com/stats
So the usage URL is http://alpha.secaudi.com/stats
Do it for other virtual hosts accordingly.
!!! AND YOU HAVE DONE IT !!!

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

five × 5 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>