tianji是一个借鉴uptime-kuma实现的网站服务器、网站服务的监控,尤其是后者,对于访问来源、页面、次数有统计,对于站长了解当前网站访问情况有帮助。

部署tianji

version: '3'
services:
  tianji:
    image: moonrailgun/tianji
#    ports:
#      - "12345:12345"
    environment:
      DATABASE_URL: postgresql://tianji:tianji@postgres:5432/tianji
      JWT_SECRET: xxx
      ALLOW_REGISTER: "false"
      ALLOW_OPENAPI: "true"
      SERVER_URL:
    depends_on:
      - postgres
    restart: always
    networks:
      tianji-network:
        ipv4_address: 172.19.3.31
  postgres:
    image: postgres:15.4-alpine
    environment:
      POSTGRES_DB: tianji
      POSTGRES_USER: tianji
      POSTGRES_PASSWORD: tianji
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      tianji-network:
        ipv4_address: 172.19.3.51

networks:
  tianji-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.19.3.0/24

在后台,新建网站,会得到一段code,实际是一段script调用脚本,放到html文件中就可以了。
2023-12-29T07:23:57.png
为了简单,我们也可以使用nginx的http_sub_module模块实现自动加入统计代码。

#PROXY-START/

location ^~ /
{
    proxy_pass http://172.18.7.31:8181;
    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;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache
    
    
    set $static_fileC8idh6S8 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
        set $static_fileC8idh6S8 1;
        expires 1m;
        }
    if ( $static_fileC8idh6S8 = 0 )
    {
    add_header Cache-Control no-cache;
    }



        sub_filter '</body>' '<script async defer src="https://tianji.op123.ren/tracker.js" data-website-id="clqqazhov002ntj7moh8djq8g"></script></body>';
        sub_filter_once on;  # 确保替换只发生一次
        sub_filter_types text/html;  # 确保只处理HTML文件

}

#PROXY-END/

2023-12-29T07:25:19.png

最后修改:2024 年 05 月 11 日
如果觉得我的文章对你有用,请随意赞赏