Awstats allows you a whole range of configurations. You are able to exclude certain IP addresses and websites from logging in Awstats. This article will discuss how to exclude certain IP addresses or websites in Awstats.
A Few Assumptions
This article assumes that you already have awstats set up on your computer, that you are using Apache, and that your DNS is setup properly. This article also assumes that your domain name is example.com (substitute example.com for whatever your domain name is).
How To Not Log Certain IP Addresses And Websites In Awstats
I like to make awstats as useful as possible. Because I visit awstats a lot, I don’t actually want my own IP address logged in awstats, because it would come up way too often. I only want to log other people’s traffic to get a more accurate picture of how much traffic I am getting. To do this, you need to edit your config file, and specifically edit the SkipHosts directive.
sudo vim example.com.conf
Find the line that says
Remove the hash or pound to the left of SkipHosts, and then you will then enter in the list of IP addresses and hosts that you don’t want to log
You can add as many entries as you want in SkipHosts. You just separate different entries by one space.
You can also use regular expressions for domains and IP address using REGEX . Put in your regular expression the regular expression for the IP addresses or domain. Use can use REGEX as aften as you want
For example, if your address of your home is 126.96.36.199, and you don’t want to log it on your server you can type:
188.8.131.52 inside the parentheses of SkipHosts = ” ”
I also don’t log the IP address where my server is and the hostname for my sever. Let’s assume that IP address is 184.108.40.206. and the hostname is samplehostname. If you don’t remember what your hostname is
you can always find it in /etc/hosts in Debian or Ubuntu. Just to be sure that my own IP address isn’t logged, I also don’t want localhost to be logged.
So far our SkipHosts file could include:
SkipHosts = "220.127.116.11 localhost 18.104.22.168"
In addition, if you have a website checking service that checks your site every 5 minutes or so, you can put that into SkipHosts. Remember, that you can use regular expressions to remove variations of a domain.
After you are done editing SkipHosts save and exit the file.
Removing Awstats Log And Apache Logs
Awstats will not remove previous logs of IP addresses or domains that you want to remove with SkipHosts. It will only prevent new hits from logging in awstats after you edit the SkipHosts directive. If you want Awstats to purge all of its logs, to start with totally new logs, here is how to do that.
You need to find out where Awstats actually stores its data logs. To do this, you need to open up your awstats config file again.
sudo vim example.com.conf
Now, look for the directive that says DirData
Whatever DirData says will be the location of where the awstats log files are stored. DO NOT EDIT THIS PART. We are just looking where it is stored.
My DirData directive says:
That means my log files are stored at /var/lib/awstats
Now exit that config file.
The following steps will require root permissions, so to make it easier, type the following:
Now you should be using the root user. Remember that you need to be SUPER careful when logged in as root user.
Next, cd to where your awstats data is stored. It may be different from what I had.
Next, you will be looking for the .txt file
For example, my domain’s txt looks like
If you are using awstats with more than 1 domain, all of the different domain text files will show up.
Now, you will delete the txt file for the domain whose log files you want to reset. type this command:
Remember to substitute in what your actual domain txt file is.
After removing that file, we are going to remove the Apache logs for our domain, to really start from scratch regarding logging.
Now, you can either remove all Apache log files here, or you could just remove the log files for your specific domain. Personally, I find it easier just to remove all log files, but you can do as you like.
That command will delete all apache log files. Now we are done with the need to be root user. Next type these commands to get out of root user
If it says you are still root user,
type exit again:
Now, awstats will temporarily not work because it has no apache files to get logs from. It may take a few seconds for apache to regenerate log files from after you deleted the previous log files.
Here is what I like to do, to make it easier. reboot your server
sudo reboot now
Next, log back into your server again. Next, become root user again temporarily
Go back to the apache log files
If you see log files, you know awstats will be able to continue. get out of root user
Finally, we can start awstats again.
sudo /usr/lib/cgi-bin/awstats.pl -config=example.com -update
Remember to substitute example.com for whatever your domain is. Now, awstats should not be logging the IP addresses and websites that you put in the SkipHosts directive.
What did you think of this article? Do you have any questions? Let’s discuss it in the comments below.