AWStats and Multiple Domains

November 9th, 2007 by

Seasons are changing, there is no doubt. There is no other place that this becomes more evident than in the WestHost Technical Support Department. With the decrease in the temperature outside we have seen an increase in the volume of contacts we see on a weekly basis. I suppose that it is inevitable, when people migrate indoors some will probably land behind a monitor and a keyboard. We are also approaching the holiday shopping season and reliability, preparedness, and tracking have become hot topics.

Recently we have seen an increase in questions regarding site statistics and how to best utilize some of our applications to analyze your site traffic. WestHost offers a great statistical application called AWStats. AWStats gives you excellent statistical information on who is visiting your site. As a Web master, you might use that data for the purpose of marketing or maintenance. For instance, AWStats tells you which search engine an end user used to find your site, and the keywords they typed in the search box. AWStats tells you how many visitors you’ve had over a given period of time, what pages they viewed, the browser they used, and a whole lot more. Many of you have asked if you can use AWStats to track multiple domains you have hosted within your single Virtual Private Server. The answer is yes you can. It is fairly easy. I will point out the key steps and common traps. I know that most of you don’t want to see anything too confusing, but would rather have a few things pointed out in plain English, so that is exactly what I intend to do. I’ll just go ahead and dive right in.

First of all, we need to have an idea of what AWStats really does on a fundamental basis. The application is going to parse the access logs that Apache keeps of all of the visitors to your site looking for visit information. From the chaos therein, it will create its own data files. Those data files will then be utilized to populate the pages that you see when you view your statistics. The problem is that by default, Apache will place all of the visit information into a single access log. Now that we understand what Apache and AWStats are going to do we can extrapolate what we need to do to accomplish our task. First we need to configure Apache to separate the access logs by domain and then AWStats to parse the separate logs accordingly. Simple enough right? Yep!

The first step is to configure Apache to write its separate access logs. This can be accomplished by editing the Apache configuration file, /etc/httpd/conf/httpd.conf. If you open and review this file, it can look confusing. I certainly thought so the first time I opened it up for some “surgery.” Not to worry. If you handle directions like the average Joe, you won’t have any trouble. Now one thing that you have to consider is that Linux doesn’t really like to interact with configuration files that have been written or edited by a text editor that will write files in a DOS format. If you are a Windows user and are not editing this file right on the server, just use Notepad, upload the edited file and you should be just fine. You could also utilize the text editor built into File Manager to complete your editing. Now that you know which file we will be editing, and just how we are going to do it, you probably want a few examples. For simplicity sake I am going to utilize and in my explanations. Once we have the config file open we will be looking for the VirtualHost entry for the secondary domain. It will be towards the bottom of the file and will look like this:

VirtualHost */>
DocumentRoot /var/www/secondarydomain

We are going to add a little something to it. We need to tell Apache that we want a custom log for this domain. We will be adding the CustomLog directive for this virtual host just below the DocumentRoot directive. Generally we will want to have the new logs written to the same directory as they would be by default, we would just want to write them to a new file name, maybe something like secondarydomain_access_log. Here is an example using the information above:

VirtualHost */>
DocumentRoot /var/www/secondarydomain
CustomLog logs/secondaryddomain_access_log combined

This entry will write the access log for to /var/log/httpd/ and it will be named secondarydomain_access_log. Once the file is modified and saved or uploaded, we will want to give Apache a nice gentle restart. This can be accomplished from within Site Manager or from the command line by issuing the “apachectl graceful” command. There is a catch to writing to separate access logs. By default they won’t be rotated. That may not sound like much but think about this, we have done such a good job to configuring Apache to write this log separately that it will happily do our bidding without question. Eventually our new log file will grow to an unmanageable size. We’ll need to talk about this later on. For now, let’s get back to our task at hand.

Now that we have got our logs separated, let’s tell AWStats what to do with them. We need new, separate config files for each of the newly separated domains. Relax, we have good templates to work with. The AWStats configuration files are located in /etc/awstats. Take a quick look at this directory. As long as you have installed AWStats you will see a file named Let’s make this a simple as possible, just make a copy of that file, but name it and save it to /etc/awstats. Now on to the fun stuff, we need to edit our new file, open the file up and let’s get to work. The first directive we need to find is the log file directive. Look for a line like the example below:


As you can see by default this configuration will pull data from the standard log. Simply change this file to point to our new log file(s). Make it look similar to the example below.


Next we need to change the SiteDomain and HostAliases directives to reflect the secondary domain name rather than the primary domain name. They will look like this and will be on line 153 and 168 or there abouts:

HostAliases=" localhost"

Modify them to reflect the secondary domain.

HostAliases=" localhost"

Now just save any changes you made. There is no need to restart anything here but we do need to check our work. Let’s see just how good we did. First we need to give Apache something to log in our new access logs so open a browser and go visit your secondary domain. Then, navigate to your AWStats Web interface, You will notice that we specified which set of stats we wanted to view by passing the config variable in the URL. Lets view the statistics for our secondary domain now, navigate to Upon initial access you may think that broke something. The statistics are not processed automatically. Not to worry, the developers of AWStats thought of this and provided us a link right at the top of the page to “update now.” Don’t hesitate, click that button, you know you want to. If all went well and you didn’t stress too much you should see a result that will contain stats that have been collected since we restarted Apache. Way to go! We are almost done.

Earlier I had made mention that the new access logs wouldn’t be rotated and eluded to the fact they would just continue to grow until they filled your disk space I also highly doubt that you want to click the “update now” button and wait for AWStats to finish updating each domain each time you want to view your statistics. Your account will already be scheduled for log rotation on a daily basis, that is unless you have edited your crontab. Ah yes, the crontab, what a wonderful tool, but we’ll leave that for another discussion. Back to logrotate, we simply need to ensure that our new logs and the AWStats updates for secondary domains are included. This is also pretty slick. We need to edit the logrotate.conf file located in the /etc/ directory. Crack it open, we’ll get this done really quickly. In that file, on about the ninth line you will see the entry for the primary access log. Here is an example:

/var/log/httpd/access_log /var/log/httpd/agent_log /var/log/httpd/error_log /var/log/httpd/
/var/log/httpd/ssl_request_log /var/log/httpd/ssl_engine_log {

Simply add your new access log files to the end of the line, but before the {

/var/log/httpd/access_log /var/log/httpd/agent_log /var/log/httpd/error_log
/var/log/httpd/referer_log /var/log/httpd/ssl_request_log /var/log/httpd/
ssl_engine_log /var/log/httpd/secondarydomain_access_log {

That will rotate our log files and manage their size. This will compress and archive our logs for a short period of time. Eventually logrotate will also delete the log files but only after adding our precious stats to the AWStats data files. Logrotate is a discussion for another time as well. Don’t close that file though, we aren’t done yet. There is one more entry we need to make to cause AWStats to update before the logs are rotated. Just below prerotate on about the 13th line of the file, you will see the following:

/usr/local/awstats/wwwroot/cgi-bin/ -update

We need to insert a new line just below it and add our secondary domain name. Just make it look like this:

/usr/local/awstats/wwwroot/cgi-bin/ -update
/usr/local/awstats/wwwroot/cgi-bin/ -update

Save your changes and give yourself a pat on the back. We are done! AWStats will now show you stats separated by domain name. We have discussed a couple of simple changes, but those simple changes will provide you some significant information.

  • Share this post

Big Boost for WestHost Affiliates!

A $50 Introduction


# 16th November, 2007

Excellent article. I cannot wait to give this a try. Thanks for posting this is such great detail. So now you know, someone is actually reading this stuff!!

I have only recently started to share domains on accounts, and this information is timely. I’ve been using AWStats for many years and will say that it is a great site stat analyzer.

Paul Rauschelbach
# 20th November, 2007

This is a great tutorial. You may want to mention the command:

/usr/local/awstats/tools/ now

which will update all the configs in /etc/awstats

Also, my prerotate statement refers to /bin/ which has the awstats update command in it. Since the logrotate script calls this script, does it need to be edited? I would think that changing the file to use the updateall script would be enough.

Brett G
# 5th December, 2007

This worked WONDERFULLY! I’ve been wanting to do this for some time but couldn’t find good directions until now.

My only problem was the permissions on my httpd.conf file — I did not have proper permission to edit the file. A quick call to Westhost support corrected that. THANKS!

# 7th January, 2008

very interesting.
i’m adding in RSS Reader

rich ferguson
# 4th February, 2008

Dan is the man! This is amazing. I will say I was going insane when altering the files from the manager online… Do not use Firefox! I was pulling my hair out because lines I was looking were not showing up the same is if I downloaded the .conf files. Crazy… Once I used another browser, it was a piece of cake. Thanks Dan!! R

Larry Katz
# 18th February, 2008

Thanks for this step by step guide. It looks simple enough but editing these configuration files really makes me nervous.

I have taken your advice to heart Rich and will try to do this with fireftp or Dreamweaver (IE as a last resort).

Mike W.
# 19th April, 2008

A great guide, but I had to chat with tech support to get it right. In the logrotate.conf file, line 13, there is a reference to /bin/ I replaced this line with the code suggested in the instructions, for each secondary domain, but I imagine you could also put these instructions in Also, I could not find an “update now” button on my version of AWSTATS (6.6 build 1.887), so I updated using SSH (or sitemanager) with the command “/usr/local/awstats/wwwroot/cgi-bin/ -update -config=sitename”. Note that this command did not work unless the .com (or other domain type) was left OFF of the command. Not exactly sure if logrotate.conf should follow the same syntax, but I changed it there as well. Now, I have stats for 6 different domains!

Rick Hocutt
# 19th May, 2008

This is a great guide thanks!

I did get stumped on this…

Upon initial access you may think that broke something. The statistics are not processed automatically. Not to worry, the developers of AWStats thought of this and provided us a link right at the top of the page to “update now.”

I didn’t have the “update now” link. After searching I found that changing the line in your awstats.mynewsite.conf file about line #238 from this:

to this:

allowed the link to appear.

# 17th August, 2008

Outstanding Article! I am not hosted by Westhost right now. I’m only poking around to see what kind of support was provided. If this is any indication of the support Westhost provides, I’m sold! My current host (also deicated IP, VDS) doesn’t provide near this detail.

# 17th August, 2008

And now that I think about it, I asked them this very question (about how to break my logs up into individual domains) and I was told it couldn’t be done! I figured it out on my own but it took me over two weeks in my spare time. I am signing up for you Summer Special when I get home.

Dan Ferry
# 27th September, 2008

Everything is as you said except the line after the prerotate line in the logrotate.conf file.

Instead of this line:

/usr/local/awstats/wwwroot/cgi-bin/ -update

I have only


Why don’t I have the line you show?

Thomas Mercer-Hursh
# 5th February, 2009

I followed through this article … and the comments (be nice to get an updated article) and I now have things working without error messages and I can see the separate logs being collected, but when I go to look at the stats with I am getting the stats for the main domain and its name shows in the upper left corner. What’s missing?

# 7th February, 2009


Just go to /bin directory and find Open it and you’ll find /usr/local/awstats/wwwroot/cgi-bin/ -update I think the new line should be inserted here for the secondary domain name.

Thomas Mercer-Hursh
# 7th February, 2009

From the forum on sourceforge, I found the answer. The config= needs to point to the short form that one has used in the configuration files, not the actual full domain name. E.g., in the configuration, I referred to bstw for and reviews for so the config= has to point to bstw and reviews respectively, not and

# 17th September, 2009

Would love to get updated instructions on this, after following them to the letter I get the same problem Excell has.

# 19th May, 2010

Thank you for writing such an appealing post. Normall I see the same thing and it starts to get on my nearves. Thanks again and I’ll be back for more.

Isaac Furniss
# 26th July, 2010

We have a more recent post for AWStats on secondary domains here:

Hope that helps.

Isaac Furniss
Technical Support Representative
Phone: 1-800-222-2165
FAX: 435-755-3449