Count Real Visitors per Website from NGINX Access Logs with Zabbix (No Tracking Script, DB-IP Lite Countries, One Page per Domain)

On this page11 sections

This post shows how to count the real people who visit each of your websites every day, with their countries, from the NGINX access logs: a Python timer sorts the visitors, Zabbix agent 2 sends the result as an active check, and a dashboard gives every domain its own page.

Why we count from the access logs instead of adding Google Analytics 4 or a self-hosted tracker (Umami, Plausible CE, Matomo) to every site, when all we need is people per day and their countries:

  • The data is already there. Every access log has each request’s address, and DB-IP Lite turns an address into a country for free.
  • No change to the sites. A tracker needs its script on every page of every site and an updated privacy page, and GA4 also needs a consent banner for visitors from the EU.
  • No extra service. A self-hosted tracker brings its own database (Plausible CE: at least 2 GB RAM, README). Here it’s a timer and Zabbix.
  • Ad blockers don’t hide visitors. A blocked script sends nothing, but the request still reaches the access log.
  • We also see who. GA4 uses the visitor’s IP address for location (and, outside the EU, spam filtering), then discards it (EU, Switzerland, UK, other regions).

What we give up: a “real person” from the logs is an estimate (rules below), with no time on page. We keep GA4 on WordPress, where Site Kit sets it up in a few clicks.

This post is based on

Lab context

  • Web server (example)
    • Host: vis-web – 172.31.169.128, Ubuntu 26.04.1 LTS, NGINX 1.28.3
    • Sites: blog.maksonlee.com, docs.maksonlee.com (one access log each)
    • Zabbix agent 2: 8.0.0 (active checks)
    • Traffic: test requests from sample addresses in several countries
  • Zabbix server: 8.0.0, at 172.31.174.72
  • Location data: DB-IP Lite City + ASN (CC BY 4.0)

What you’ll build

  • Per site and per day: people, page views, countries, a day-by-day table and who visited

Who counts as a person (address + user agent, per site, per day):

  • Left out: bots and tools, non-browsers, private addresses, data-centre networks (DB-IP ASN owner)
  • Confirmed: a page view plus a CSS, JS, font or image file, a service worker or an /api/ call that day, or a confirmation in the last 30 days
  • Unconfirmed: counted, not listed (mostly scrapers that fetch HTML only)

Prerequisites

  • Zabbix agent 2 with active checks (steps 1 and 5 of the previous post)
  • One access log per site, NGINX’s default combined format
  • Static files logged: no access_log off in a location that serves CSS, JS or images. Check:
sudo grep -rn 'access_log off' /etc/nginx/sites-enabled/

1. Download the files

On the web server:

sudo apt install -y python3-maxminddb unzip
wget -q https://www.maksonlee.com/wp-content/uploads/2026/11/website-visitors-1.1.zip
unzip -q website-visitors-1.1.zip && cd website-visitors-1.1

Keep the zip on your PC too: step 4 imports its template.

2. Install the location data (DB-IP Lite, monthly)

Install:

sudo install -D -m 755 dbip_update.py /usr/local/lib/visitor-stats/dbip_update.py
sudo install -m 644 visitor-geo-update.service visitor-geo-update.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now visitor-geo-update.timer
sudo systemctl start visitor-geo-update.service

Check:

sudo journalctl -u visitor-geo-update.service -o cat --grep 'installed:'

Expected (example):

DB-IP Lite 2026-11 installed: dbip-city-lite.mmdb DBIP-City-Lite 126873350 bytes, dbip-asn-lite.mmdb DBIP-ASN-Lite (compat=GeoLite2-ASN) 9648279 bytes

The timer repeats it on the 5th of every month. Credit “IP Geolocation by DB-IP” where you show the data.

3. Install the statistics (every 5 minutes)

Create the directory:

sudo install -d /etc/visitor-stats

Create /etc/visitor-stats/config.json, one entry per site:

{
  "timezone": "Asia/Taipei",
  "geoip": {
    "kind": "files",
    "city": "/var/lib/visitor-stats-geo/dbip-city-lite.mmdb",
    "asn": "/var/lib/visitor-stats-geo/dbip-asn-lite.mmdb",
    "info": "/var/lib/visitor-stats-geo/installed.json"
  },
  "sites": [
    {"name": "blog.maksonlee.com", "log": "/var/log/nginx/blog.access.log", "format": "combined"},
    {"name": "docs.maksonlee.com", "log": "/var/log/nginx/docs.access.log", "format": "combined"}
  ]
}

Optional: waf_audit (the ModSecurity audit log, flagged addresses don’t count) and complete_from (the first full day).

Install and run it once:

sudo install -m 755 visitor_stats.py /usr/local/lib/visitor-stats/
sudo install -m 644 visitor-stats.service visitor-stats.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now visitor-stats.timer
sudo systemctl start visitor-stats.service
sudo ls -l /var/lib/visitor-stats/

Expected (example):

total 16
-rw------- 1 root root    235 Nov 29 05:44 daily.json
drwx------ 2 root root   4096 Nov 29 05:44 days
-rw------- 1 root root    553 Nov 29 05:44 state.json
-rw-r----- 1 root zabbix 3241 Nov 29 05:44 stats.json

It reads only new lines, and the agent reads stats.json, not the logs. Addresses stay 14 days in days/.

Read the first site’s table:

sudo python3 -c 'import json; print(json.load(open("/var/lib/visitor-stats/stats.json"))["sites"][0]["days"])'

Expected (example):

2026-11-29 (so far)      7 people     10 page views  JP 1, US 1, GB 1, AU 1, CA 1, SG 1

4. Import the template (Zabbix)

  • Data collection → Templates → Import → website-visitors-by-zabbix-agent-active.yaml from the zip → Import → Import
  • Data collection → Hosts → the web server’s host → Templates → Website visitors by Zabbix agent active → Update
The Added list of the template import
The host form with the Website visitors template

Discovery adds 11 items per site within 5 minutes. A trigger fires when stats.json is 30 minutes old.

5. Build the dashboard (one page per domain)

  • User settings → API tokens → Create API token → copy the token

Still in the zip’s directory on the web server, paste the token at the prompt:

read -rsp 'Zabbix API token: ' ZABBIX_TOKEN && echo && export ZABBIX_TOKEN
ZABBIX_URL=http://172.31.174.72:8080 python3 make_dashboard.py vis-web

Expected (example):

Zabbix API token: 
Created dashboard 439 (Website visitors: all sites): 2 domains, 3 pages

Run it again after adding a site: it updates the same dashboard.

6. Verify

Dashboards → Website visitors: all sites shows every domain on All sites (a line’s daily peak is that day’s total), then one page per domain with Day by day, countries and Who visited.

People today and yesterday per domain on the All sites page
The numbers and the Day by day table of one domain
Countries and Who visited today on the domain page

Summary

You now have the real people and their countries per domain per day in Zabbix, straight from the access logs.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top