a lightweight, secure, fast page view tracker

Toronto, 2017.10.13

A year ago, I designed a lightweight, anonymous page-view counter for my website: 75,000 views later I'm sharing with the world.

First, the design considerations:

Those are a lot of conflicting requirements!

After trying several designs, I realized that what I was looking for was:

  1. A small CSS file that contained some useful part of the site's design. But not too much.
  2. A subdomain of emuu.net (and my other website, risktopics.com) that allowed me to cache all of the main content, and put a strict no-cache configuration on the tracker-lite CSS. A simple nginx configuration block was all I needed to separate the tracker from the content.

The CSS code loaded from the subdomain can be anything. In my case, I went with the CSS that loads the fonts.

Here's the nginx.conf bit that identifies 'bot traffic:

map $http_user_agent $bot { ~*(google|bing|pingdom|monitis.com|Zend_Http_Client) 1; ~*(http|crawler|spider|bot|search|ForusP|Wget/|Python-urllib|PHPCrawl|bGenius) 1; default 0; access_log off; } log_format ww '$time_iso8601 $host $http_referer $bot $remote_addr';

Note that this doesn't actually stop 'bot traffic from being logged. But it does flag bad page views with a '1' whereas good traffic is a '0'. I then discard the bot "page views" in the script that reports on the traffic.

Here's the nginx config block for the subdomain(s):

server { listen 80; server_name ww.emuu.net ww.risktopics.com; charset utf-8; root /yadda/yadda/emuu.net/ww; index index.html; error_log /dev/null; access_log /yadda/yadda/emuu.net/logs/ww_access.log ww; location /fonts.css { expires 0; add_header Cache-Control private; } }

Note that this contrasts with the caching directive for the main site, which looks like:

add_header Cache-Control "public"; expires 1y;

leave a comment

By submitting this form you agree to the privacy terms.
 

rand()m quote

(In which I leave the final word to someone else.)

Naturally the common people don't want war: Neither in Russia, nor in England, nor for that matter in Germany. That is understood. But, after all, it is the leaders of the country who determine the policy and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship. Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked, and denounce the peacemakers for lack of patriotism and exposing the country to danger. It works the same in any country.

-Hermann Goering

privacy · copyright · sitemap · website traffic