How to install Fathom Analytics on nginx?

Fathom Analytics is a simple and privacy-focused alternative to Google Analytics.

While they offer a PRO version of their application starting from $14/month, they do offer an option to selfhost the application on their GitHub repository.

This tutorial assumes you already have a running nginx server on Debian/Ubuntu.

Download the latest release from GitHub (v1.2.1 at time of posting).

wget https://github.com/usefathom/fathom/releases/download/v1.2.1/fathom_1.2.1_linux_amd64.tar.gz
tar -xvf fathom_1.2.1_linux_amd64.tar.gz
chmod +x fathom
sudo mv fathom /usr/local/bin

Create a .env configuration file with the following contents:

FATHOM_SERVER_ADDR=9000
FATHOM_DEBUG=true
FATHOM_DATABASE_DRIVER="sqlite3"
FATHOM_DATABASE_NAME="fathom.db"
FATHOM_SECRET="random-secret-string"

Create a new file /etc/systemd/system/fathom.service with the following contents. Replace $USER with your username.

[Unit]
Description=Fathom server management service unit
Requires=network.target
After=network.target

[Service]
Type=simple
User=$USER
Restart=always
RestartSec=3
WorkingDirectory=/home/$USER
ExecStart=/usr/local/bin/fathom server

[Install]
WantedBy=multi-user.target

Reload the Systemd configuration and enable the service to start on boot.

sudo systemctl daemon-reload
sudo systemctl enable fathom.service
sudo systemctl start fathom.service

Add the following to your nginx server block configuration. Modify accordingly.

server {
server_name fathom.example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://YOURSERVERIPADDRESS:9000;
}
}

Test the nginx server configuration and restart nginx.

sudo nginx -t
sudo systemctl restart nginx

In order to use your Fathom installation to track multiple sites, the dashboard must be set to private. Create a user account to do so:

fathom user add [email protected] --password=secret

After you’re done adding your sites, you can safely delete the user again like so:

fathom user delete [email protected]

Navigate to the Fathom install location and login to get started.

That’s it!

2020-01-05

index