--- title: 【记录】搭建流量统计工具 Shynet urlname: Building-a-traffic-statistics-tool-Shynet index_img: https://api.limour.top/randomImg?d=2024-03-25 12:52:28 date: 2024-03-25 20:52:28 tags: hexo --- [Shynet](https://github.com/milesmcc/shynet) 是一款用 python 编写的现代、隐私友好、无需Cookie或JS即可工作的网络流量统计工具。 相比 [Umami](https://github.com/umami-software/umami), Shynet 支持通过 1 pixel 的图像进行统计,而不依赖 JS, 并且 Shynet 统计的信息更加详细。 ![最终效果](https://img.limour.top/2024/03/25/660177c20629f.webp) ## 搭建 Shynet + [反向代理服务](/Docker-bu-shu-Nginx-Proxy-Manager) ```bash mkdir -p ~/app/shynet && cd ~/app/shynet && nano docker-compose.yml ``` ```yml version: '3.6' services: shynet: image: milesmcc/shynet:latest restart: always env_file: - .env volumes: - ./db:/var/local/shynet/db/ - /etc/localtime:/etc/localtime:ro networks: default: external: true name: ngpm ``` + 配置环境变量 ```bash wget -O .env https://github.com/milesmcc/shynet/raw/master/TEMPLATE.env # 注释掉 .env 中 PostgreSQL 相关的部分,启用 SQLITE 相关的部分 # 注释掉 .env 中 Email 相关的部分 # 按说明生成 DJANGO_SECRET_KEY # 修改 ALLOWED_HOSTS 和 CSRF_TRUSTED_ORIGINS # 语言换成中文 LANGUAGE_CODE=zh-cn # 时区换成上海 TIME_ZONE=Asia/Shanghai mkdir -p db && chmod 777 db sudo docker-compose up -d # 反代 shynet:8080 ``` + 配置管理账号 ```bash sudo docker-compose exec -it shynet ./manage.py registeradmin # 控制台输出如下信息 # Email address: # Password: ``` ## 配置混淆 ```nginx sub_filter 'https://xxx/ingress/' 'https://xxx/vue/'; sub_filter_once off; sub_filter_types application/javascript; ``` ![](https://img.limour.top/2024/03/25/6601762cad36c.webp) ## 配置 Hexo + [搭建 Hexo](/-ji-lu--zai-GitHub-shang-da-jian-Hexo) + 编辑 `scripts/custom.js`, 内容如下 ```js // shynet 统计 hexo.extend.injector.register('head_begin', ` `); ```