Real IP AWStats

Obtaining the real IP for AWStats when using Varnish

Habschned
Habschned

Ever since i installed Varnish Cache on the server to speed up website delivery and overall performance i had no visitors showing up in AWStats except for one, the IP of the Varnish server. From the technical side of things that is perfectly fine, since the only IP/Visitor accessing Apache is Varnish which runs locally. But i wanted to have visitors show up in AWStats again, i kinda like to see how many unique visitors, pageviews, etc. the site receives without having to resort to services like Google Analytics.

Well, this has been bugging me for a while now and today i took the time to look a little closer into getting it sorted and setup everything in a way that AWStats can log the real IPs of visitors again and display its statistics. There are different approaches, one of them would be reinstalling AWStats from scratch, messing around with the log file formats and some other, highly complicated stuff. Since AWStats was working fine before the installation of Varnish i felt no need to reinstall it.

So here is how i fixed it without having to reinstall AWStats and mess with the Apache log file format. Since i am using cPanel and Apache i decided to use the mod_rpaf module. mod_rpaf doesn’t come with a standard cPanel/WHM installation, so it need to be installed first before you can use it. To download and install it run the commands below in your command line

When done you need to load the mod_rpaf module into your Apache configuration. To do so login to your WHM interface, open Service Configuration > Apache Configuration > Include Editor > Pre Main Include and select All Versions from the dropdown list, then paste the text below the screenshot into the editor:

WebHost Manager
WebHost Manager

Here is the text to paste:

When pasting, make sure you edit the IP address (111.111.111.111 in the above example) to match the IP of your server.  When done pasting and changing the IP click Update and then restart Apache to apply the changes. Now there is just one step left to do before you have your AWStats functionality back when running cPanel/WHM and Varnish. To make cPanel remember that Apache configuration template has changed we need to run the following commands:

And that’s it. You can now quit your terminal/shell session and AWStats should log visitors just fine.

2 Comments

    • Nope,
      i guess every basic cPanel user that adds Varnish Cache to his VPS or Dedicated will eventually run into this problem (if he uses any of the stats tools cPanel offers)

Leave a Reply

Your email address will not be published.


*


* The confirmation to GDPR is mandatory.

I confirm

This site uses Akismet to reduce spam. Learn how your comment data is processed.