Hugo博客公告弹窗

Nginx 网站日志分析工具

项目:https://github.com/BeyondXinXin/nixvis

NixVis 是一款基于 Go 语言开发的、开源轻量级 Nginx 日志分析工具,专为自部署场景设计。它提供直观的数据可视化和全面的统计分析功能,帮助您实时监控网站流量、访问来源和地理分布等关键指标,无需复杂配置即可快速部署使用。

go安装

如果没有安装

wget https://golang.org/dl/go1.25.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.25.5.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc && source ~/.bashrc
go version

放行防火墙

ufw allow 8089/tcp

快速开始

  1. 下载最新版本的 NixVis
wget https://github.com/beyondxinxin/nixvis/releases/download/latest/nixvis
chmod +x nixvis
  1. 生成配置文件
./nixvis -gen-config

执行后将在当前目录生成 nixvis_config.json 配置文件。

nixvis_config.json 模板参考


{
  "websites": [
    {
      "name": "blog",
      "logPath": "/home/nginx/log/www.1234.com-*.log"
    },
    {
      "name": "web",
      "logPath": "/home/nginx/log/www.5678.cc-*.log"
    }
  ],
  "system": {
    "logDestination": "file",
    "taskInterval": "5m"
  },
  "server": {
    "Port": ":8089"
  },
  "pvFilter": {
    "statusCodeInclude": [
      200
    ],
    "excludePatterns": [
      "favicon.ico$",
      "robots.txt$",
      "sitemap.xml$",
      "\\.(?:js|css|jpg|jpeg|png|gif|svg|webp|woff|woff2|ttf|eot|ico)$",
      "^/(?:api|ajax)/",
      "^/index\\.php/ajax/",
      "^/index\\.php/user/ajax_ulog$",
      "^/health$",
      "^/_(?:nuxt|next)/",
      "rss.xml$",
      "feed.xml$",
      "atom.xml$"
    ]
  }
}
  1. 编辑配置文件 nixvis_config.json,添加您的网站信息和日志路径
  • 支持日志轮转路径 (#2)
  • 支持 PV 过滤规则 (#21)
  1. 后台启动
nohup ./nixvis > /root/nixvis.log 2>&1 &

访问 Web 界面 http://localhost:8089

停止进程

ps aux | grep nixvis

然后

kill -9 <PID>

或者使用以下方式启动

启动

  1. 创建 systemd 服务文件:

    sudo nano /etc/systemd/system/nixvis.service
    
  2. 在文件中添加以下内容:

    [Unit]
    Description=NixVis Service
    After=network.target
    
    [Service]
    Type=simple
    ExecStart=/root/nixvis
    WorkingDirectory=/root
    StandardOutput=file:/root/nixvis.log
    Restart=always
    User=root
    
    [Install]
    WantedBy=multi-user.target
    
  3. 重新加载 systemd 配置并启动服务:

    sudo systemctl daemon-reload
    sudo systemctl start nixvis
    
  4. 启动时自动启动 NixVis:

    sudo systemctl enable nixvis
    
  5. 查看 NixVis 服务的状态:

    sudo systemctl status nixvis
    
  6. 访问 Web 界面 http://localhost:8088

CC BY-NC-SA 4.0 转载请注明
最后更新于 2026-01-02 08:00