Technitium DNS server zone high-availability

Awstats log analyzer for Postfix

AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages. It uses a partial information file to be able to process large log files, often and quickly. It can analyze log files from all major server tools like Apache log files (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C log format) and a lot of other web, proxy, wap, streaming servers, mail servers and some ftp servers.

1. Install awstats and apache2.

sudo apt-get install awstats apache2

* Oracle Cloud VPS ubuntu cloud image exclude configuration example file installation in dpkg by default. Comment out /etc/dpkg/dpkg.cfg.d/excludes as we require some example files from awstats.

2. Setup /etc/awstats/awstats.postfix.conf for your postfix log.

sudo mv /etc/awstats/awstats.conf /etc/awstats/awstats.conf.default
sudo cp /etc/awstats/awstats.conf.default /etc/awstats/awstats.postfix.conf
3. Edit /etc/awstats/awstats.postfix.conf with below settings.
LogFile="/usr/share/doc/awstats/examples/maillogconvert.pl standard < /var/log/mail.log |"

LogType=M

LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"

SiteDomain="mydomain.com"

LevelForBrowsersDetection=0
LevelForOSDetection=0
LevelForRefererAnalyze=0
LevelForRobotsDetection=0
LevelForSearchEnginesDetection=0
LevelForKeywordsDetection=0
LevelForFileTypesDetection=0
LevelForWormsDetection=0

ShowMonthStats=UHB
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=0
ShowHostsStats=HBL
ShowRobotsStats=0
ShowEMailSenders=HBML
ShowEMailReceivers=HBML
ShowSessionsStats=0
ShowPagesStats=0
ShowFileTypesStats=0
ShowOSStats=0
ShowBrowsersStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=1

4. Test run awstats.

sudo /usr/lib/cgi-bin/awstats.pl -config=postfix -update

5. Configure apache2 for awstats.

sudo cp /usr/share/doc/awstats/examples/apache.conf /etc/apache2/conf-available/awstats.conf 
sudo a2enmod cgi
sudo systemctl restart postfix

6. Open awstats URL (http://xxx.xxx.xxx.xxx/cgi-bin/awstats.pl?config=postfix) in web browser.

7. Edit /etc/cron.d/awstats to update the awstats data as root.

8. To use HTTPS instead of HTTP, edit your default sites (/etc/apache2/sites-available/000-default.conf) to redirect to HTTPS.

#Replace xxx.xxx.xxx.xxx with your server IP or hostname 
Redirect permanent / https://xxx.xxx.xxx.xxx/

9. Optional: Enable SSL module and the HTTPS sites configuration.

sudo a2enmod ssl
sudo a2ensite default-ssl.conf
sudo systemctl restart apache2

10. Open awstats URL (http://xxx.xxx.xxx.xxx/cgi-bin/awstats.pl?config=postfix) again and it should redirect your awstats webpage to HTTPS.

11. Optional: To enable password authentication, create your credential using htpasswd.

sudo htpasswd -c /etc/apache2/htpasswd admin

12. Add below config text to your HTTPS site configuration files (/etc/apache2/sites-available/default-ssl.conf).

AuthUserFile /etc/apache2/htpasswd
AuthName "Please Enter Your Password"
AuthType Basic
Require valid-user

13. Restart apache2 service and refresh the awstats webpage. It will prompt for the authentication page.


 



Comments