Umami是一个开源的Self-hosted的轻量网站统计分析工具。可替代Google Analytics百度统计这些工具。适合个人博客、小型网站使用。

安装

服务器有Node.js运行时的,可以安装Node.js版本。官网有文档介绍,在此略过。

Dockser-compose

在域名目录下新建 compose.yml文件:

vim compose.yml
services:
  umami:
    image: sparanoid/umami:postgresql-latest
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgresql://umami:umami@db:5432/umami
      DATABASE_TYPE: postgresql
      APP_SECRET: replace-me-with-a-random-string
      TRACKER_SCRIPT_NAME: "custom-script-name.js"

    depends_on:
      db:
        condition: service_healthy
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "curl http://localhost:3000/api/heartbeat"]
      interval: 5s
      timeout: 5s
      retries: 5
  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: umami
      POSTGRES_USER: umami
      POSTGRES_PASSWORD: umami
    volumes:
      - umami-db-data:/var/lib/postgresql/data
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 5
volumes:
  umami-db-data:

启动容器

docker-compose up -d

此时,打开 http://server_ip:3000即可登录Umami开始使用了。

  • 默认账号:admin
  • 默认密码:umami

Nginx反代

如果不想直接使用服务器的IP登录和暴露端口,可以利用Nginx反代。假设使用 ana.umami.com 这个二级域名来当作Umami的域名。

server
{
    listen 80;
    listen 443 ssl ;
    http2 on;
    server_name ana.umami.com;
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }


    # 反代配置
    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 X-Forwarded-Proto $scheme;
    proxy_set_header REMOTE-HOST $remote_addr;
    add_header X-Cache $upstream_cache_status;
    # 缓存
    add_header Cache-Control no-cache;
    expires 12h;
  }
}

反屏蔽

广告插件反屏蔽

Umami的默认跟踪代码是被大多数的广告插件屏蔽的,被屏蔽了你就统计不到访客信息了。如果需要反屏蔽,需要在 compose.yml 文件中添加环境变量:TRACKER_SCRIPT_NAME,如:

    environment:
      TRACKER_SCRIPT_NAME: random-string.js

然后获取到的跟踪代码的 src 会变成:

srcipt.js => random-string.js

- https://tongji.notumami.com/script.js
+ https://tongji.notumami.com/random-string.js

官方文档提供了更多的环境变量配置: https://umami.is/docs/environment-variables

标签: docker, umami, 网站统计, Analytics

添加新评论