Publish: 2022-05-16 | Modify: 2022-05-16
On May 10, 2022, U-Web (CNZZ/Umeng) announced the closure of services for all unpaid accounts. You can refer to the announcement here. There are many alternative products available, such as Baidu Analytics and 51la in China, and Google Analytics internationally. If you're not satisfied with any of these options, you can also consider self-hosted website analytics solutions like Umami, Plausible, or Matomo. Today, let's talk about Umami as one of the self-hosted solutions.
According to the official website:
Umami is a simple, easy-to-use, self-hosted web analytics solution. The goal is to provide you with a more friendly, privacy-focused alternative to Google Analytics, as well as a free and open-source alternative to paid solutions. Umami only collects the metrics you care about and presents them on a single page.
Prerequisites:
My Setup:
Since everyone's environment may be different, this article may not apply to everyone, but it can serve as a reference. I already have MySQL installed on my server, so when deploying with Docker, I didn't need to install MySQL separately. I simply used the existing MySQL installation.
Importing the Database:
I have already created a database named umami
and imported the initial data schema.mysql.sql
.
Deploying Umami with docker-compose
If you haven't installed docker-compose yet, please refer to the official documentation for installation: Install docker-compose
Using docker-compose
for deployment makes it easier for maintenance and management. You need to create a docker-compose.yaml
file with the following content:
---
version: '3'
services:
umami:
image: ghcr.io/mikecao/umami:mysql-latest
ports:
- "3000:3000"
environment:
DATABASE_URL: mysql://username:[email protected]:3306/umami
DATABASE_TYPE: mysql
HASH_SALT: replace-me-with-a-random-string
restart: always
network_mode: "host"
The parameters in the file should be modified according to your own situation:
username
: MySQL usernamepassword
: MySQL password127.0.0.1:3306
: MySQL connection address and portumami
: MySQL database nameHere, I used the HOST network, network_mode: "host"
, because my MySQL is set up on the host machine. If you don't specify the HOST network, it won't be able to communicate with Docker.
To start, simply run the command docker-compose up -d
.
After the setup, Umami will be available on port 3000
. You can access it using http://IP:3000
. The default username is admin
and the password is umami
.
The default interface is in English. After logging in, you can click the "globe" icon in the top right corner to switch to Chinese.
Accessing Umami through IP and port is only suitable for temporary testing and not recommended for production. You can use Nginx reverse proxy to enable domain access.
Here is an example Nginx reverse proxy configuration. Please modify it according to your actual situation:
server {
listen 80;
listen 443 ssl http2;
server_name domain.com;
index index.php index.html index.htm default.php default.htm default.html;
# SSL configuration, please don't delete or modify the following line
# error_page 404/404.html;
# Redirect HTTP to HTTPS
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#SSL-END
# Other configuration...
location ^~ / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
# Additional proxy settings...
}
# Other configuration...
}
If you are using the Baota control panel, you can also use its reverse proxy feature. Simply follow the instructions in the screenshot.
Umami has a simple interface with limited options, making it easy to get started. In terms of functionality, it is sufficient but not as feature-rich as Baidu Analytics or Google Analytics. It still has a long way to go to replace these commercial analytics solutions.
admin
, and the password is umami
.I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.