AWStats: Complete Guide to Settinging Up and Configuring AnalyticsAWStats is a powerful, open-source log analyzer that generates advanced web, streaming, ftp or mail server statistics graphically. It reads server log files and produces visual, detailed reports about visits, traffic sources, pages, bots, and more. This guide walks through installation, configuration, log handling, security considerations, customization, and troubleshooting to help you deploy AWStats effectively for single or multiple sites.
What AWStats Does and When to Use It
AWStats analyzes server log files (Apache, Nginx, IIS, proxy logs, mail servers, FTP servers) and generates HTML reports with charts and tables. Unlike JavaScript-based analytics (e.g., Google Analytics), AWStats works even when users disable JavaScript or block third-party trackers because it relies on server-side logs. Use AWStats when you need:
- Accurate server-side counts including bots and crawlers.
- Historical analysis from archived logs.
- Analytics without client-side code or third-party tracking.
- Detailed per-file or per-extension statistics (downloads, images).
- Low-cost, privacy-friendly analytics under your control.
Prerequisites
- A Unix-like server (Linux, BSD) or Windows with Perl installed.
- Web server (Apache, Nginx, IIS) to host AWStats HTML output and CGI interface (optional).
- Access to server log files (e.g., /var/log/apache2/access.log) or the ability to rotate and feed logs into AWStats.
- Basic knowledge of shell, file permissions, and web server configuration.
Installation
1) Install required packages
On Debian/Ubuntu:
sudo apt update sudo apt install awstats perl libgeo-ipfree-perl
On CentOS/RHEL (EPEL may be needed):
sudo dnf install epel-release sudo dnf install awstats
On Windows, download AWStats from the official site and install Perl (e.g., Strawberry Perl), then place AWStats files into a directory served by IIS or run CGI.
2) Verify Perl modules
AWStats uses Perl and several optional modules (GeoIP, Encode). Check with:
perl awstats.pl -check
Install missing modules via your package manager or CPAN:
cpan install Geo::IP
3) Create a configuration file
AWStats ships with a sample configuration (awstats.conf). Create a site-specific config by copying:
sudo cp /etc/awstats/awstats.conf /etc/awstats/awstats.mysite.conf
Key parameters to set:
- LogFile — path to your log, or use “LogFile=”/usr/lib/cgi-bin/awstats.pl?config=mysite&logfile=/path/to/log”” for remote logs.
- SiteDomain — domain name (example.com).
- HostAliases — alternative hostnames.
- DirData — where AWStats stores its processed data (e.g., /var/lib/awstats).
- LogFormat — your server log format; AWStats supports common formats like 1 (NCSA combined), 4 (IIS), etc.
Example minimal edits in awstats.mysite.conf:
LogFile="/var/log/apache2/access.log" SiteDomain="example.com" HostAliases="localhost 127.0.0.1 example.com www.example.com" DirData="/var/lib/awstats" LogFormat=1
Processing Logs (Command-Line Mode)
AWStats can be run manually or via cron to process logs into monthly data files.
Basic command to update stats:
sudo awstats.pl -config=mysite -update
This reads the LogFile, parses new entries, and updates data files in DirData.
To process a specific log file (useful for rotated logs):
sudo awstats.pl -config=mysite -logfile=/path/to/logfile -update
To build static HTML pages without CGI:
sudo awstats_buildstaticpages.pl -config=mysite -dir=/var/www/html/awstats
Web Interface (CGI) Setup
AWStats includes a CGI script to view stats dynamically.
For Apache
- Enable CGI and copy the CGI script:
sudo a2enmod cgi sudo cp /usr/lib/cgi-bin/awstats.pl /usr/lib/cgi-bin/ sudo chown root:root /usr/lib/cgi-bin/awstats.pl sudo chmod 755 /usr/lib/cgi-bin/awstats.pl
- Configure a site alias in Apache config:
Alias /awstatsclasses "/usr/share/awstats/lib/" Alias /awstatsicons "/usr/share/awstats/icon/" ScriptAlias /awstats/ "/usr/lib/cgi-bin/awstats.pl/"
- Restart Apache:
sudo systemctl restart apache2
- Secure access using basic auth or IP restriction in Apache:
<Location /awstats> AuthType Basic AuthName "AWStats" AuthUserFile /etc/awstats/.htpasswd Require valid-user </Location>
For Nginx
Nginx does not execute CGI natively. Use fcgiwrap or build static pages with awstats_buildstaticpages.pl and serve them.
Configuring Log Formats
Common LogFormat settings:
- Apache combined: LogFormat=“%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot” (LogFormat=1)
- IIS and other servers have dedicated LogFormat codes.
If you use custom log formats, set LogFormat= and provide a format string in awstats config (see AWStats documentation).
Filtering and Excluding Traffic
Exclude internal IPs and bots via the config:
- SkipHosts: list IPs or CIDRs to ignore (e.g., 10.0.0.0/8).
- SkipUserAgents: patterns to ignore certain user agents.
- SkipReferrers: ignore specific referrers.
Example:
SkipHosts="192.168.0.0/16 10.0.0.0/8" SkipUserAgents="Googlebot Yahoo! Slurp"
To treat known bots separately, AWStats already has bot detection; ensure GeoIP and robot definitions are up to date.
Multiple Sites and Virtual Hosts
Create a config per site (awstats.site1.conf, awstats.site2.conf) with appropriate LogFile and SiteDomain. Use one cron job that runs awstats.pl -update for each config, or a script to iterate through configs.
Example cron:
0 */2 * * * /usr/bin/awstats.pl -config=site1 -update 0 */2 * * * /usr/bin/awstats.pl -config=site2 -update
Custom Reports and Plugins
AWStats supports plugins to extend parsing and reporting:
- Install plugins by placing them in the awstats plugin directory (commonly /usr/share/awstats/plugins).
- Enable plugins in the config with LoadPlugin. Example:
LoadPlugin=anonymizeip LoadPlugin=virtualpages
Virtual pages let you group dynamic URLs (e.g., product?id=123) into meaningful pages.
Performance and Large Logs
For high-traffic sites:
- Pre-process rotated logs and feed them incrementally to avoid re-parsing full logs.
- Increase DirData location on large disk with fast I/O.
- Use the -update option instead of -config to process only new entries.
- Build static pages periodically rather than running CGI on demand.
Security and Privacy
- Restrict AWStats web access (Basic Auth, IP allowlists).
- Ensure DirData and configuration files are readable only by necessary users.
- If hosting AWStats publicly, be mindful that reports reveal site traffic patterns; use anonymization plugins if needed.
Troubleshooting
- “No data found” — confirm LogFile path and permissions, check LogFormat.
- “Unknown log format” — set correct LogFormat or use -logfile with a known format.
- Permissions errors — ensure AWStats can read logs (or run updates as root via cron) and write to DirData.
- Incorrect counts — check SkipHosts/SkipUserAgents and rotated log handling.
Useful diagnostic commands:
perl /usr/lib/cgi-bin/awstats.pl -config=mysite -update -debug
Maintenance and Best Practices
- Rotate logs regularly and process rotated files to keep AWStats up to date.
- Update AWStats and its robot/geoip databases.
- Use per-site configs for clarity.
- Automate updates and static page builds via cron or systemd timers.
- Periodically archive DirData for long-term retention.
Example: Minimal Cron for Two Sites
# Update AWStats every hour for two sites 0 * * * * /usr/bin/perl /usr/lib/cgi-bin/awstats.pl -config=site1 -update >/dev/null 2>&1 15 * * * * /usr/bin/perl /usr/lib/cgi-bin/awstats.pl -config=site2 -update >/dev/null 2>&1
Conclusion
AWStats is a robust, privacy-respecting analytics tool that excels at server-side log analysis. With proper configuration, log handling, and security, it provides detailed insights without client-side trackers. Follow the steps above to install, configure, and maintain AWStats for accurate, long-term analytics.
Leave a Reply