切換選單
切換偏好設定選單
切換個人選單
尚未登入
若您做出任何編輯,會公開您的 IP 位址。

BandwagonHost安裝哪吒監控(Nezha Monitoring) Nginx 反代 HTTPS 完整教程

出自md5.pw
於 2026年1月28日 (三) 00:53 由 Byte6b留言 | 貢獻 所做的修訂
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)

BandwagonHost安裝哪吒監控(Nezha Monitoring)+ Nginx 反代 + HTTPS 完整教程

一、什麼是哪吒監控(Nezha Monitoring)

哪吒監控(Nezha Monitoring)是一款開源、自託管、輕量級的服務器與網站實時監控和運維工具。它支持通過 Dashboard 查看系統狀態、資源使用情況,並通過 Agent 採集被監控主機數據。

在本文中,我們將一步一步教你如何從零開始在BandwagonHost(搬瓦工) 機器上使用docker安裝與部署哪吒監控(Nezha Monitoring)系統的 Dashboard 面板,使用nginx反代Dashboard,並配合 Agent 安裝與基本配置內容。

二、部署前的準備

1、服務器與網絡條件:

  • 一台 BandwagonHost(搬瓦工) 者其他可以訪問公網的服務器
  • 服務器防火牆和安全策略需允許 Dashboard 使用的端口(默認是 8008)
  • 推薦的規格:單核 + 512MB 內存 對於大部分場景足夠。

2、域名設置

  • 一個已設置好 A 記錄 指向 Dashboard 服務器 IP 的域名
  • 如果面板端使用 CDN,還建議準備第二個域名用於 Agent 通信(不通過 CDN)

三、安裝 Dashboard 面板

1. 運行官方安裝腳本

在你的 Dashboard 服務器終端執行以下命令來獲取並運行官方安裝腳本:

curl -L https://raw.githubusercontent.com/nezhahq/scripts/refs/heads/main/install.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh

如果你的服務器位於中國大陸,可以使用鏡像:

curl -L https://gitee.com/naibahq/scripts/raw/main/install.sh -o nezha.sh && chmod +x nezha.sh && sudo CN=true ./nezha.sh



在瀏覽器中輸入 http://your_server_ip:8008 可以訪問哪吒監控的 Web 界面

四、使用nginx反代

1、安裝nginx

sudo apt update
sudo apt install -y nginx

啟動並設置開機自啟:

sudo systemctl start nginx
sudo systemctl enable nginx

2、申請證書

  1. 安裝 Certbot + Nginx 插件 Certbot 是 Let's Encrypt 官方推薦的證書管理工具python3-certbot-nginx 插件可以 自動修改 Nginx 配置。
    sudo apt install certbot python3-certbot-nginx
    安裝完成後,檢查版本:
    certbot --version
    
  2. 申請證書
    sudo certbot --nginx -d 你的域名
    

3、配置nginx配置文件

文件路徑一般在 /etc/nginx/sites-available/default

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name dashboard.example.com; # 替换为你的域名
    ssl_certificate          /data/letsencrypt/fullchain.pem; # 域名证书路径
    ssl_certificate_key      /data/letsencrypt/key.pem;       # 域名私钥路径
    ssl_stapling on;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:10m; # 如果与其他配置冲突,请注释此项
    ssl_protocols TLSv1.2 TLSv1.3;

    underscores_in_headers on;

    # grpc 相关    
    location ^~ /proto.NezhaService/ {
        grpc_set_header Host $host;
        grpc_set_header nz-realip $remote_addr;
        grpc_read_timeout 600s;
        grpc_send_timeout 600s;
        grpc_socket_keepalive on;
        client_max_body_size 10m;
        grpc_buffer_size 4m;
        grpc_pass grpc://dashboard;
    }
    # websocket 相关
    location ~* ^/api/v1/ws/(server|terminal|file)(.*)$ {
        proxy_set_header Host $host;
        proxy_set_header nz-realip $remote_addr; 
        proxy_set_header Origin https://$host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;
        proxy_pass http://127.0.0.1:8008;
    }
    # web
    location / {
        proxy_set_header Host $host;
        proxy_set_header nz-realip $remote_addr;
        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;
        proxy_buffer_size 128k;
        proxy_buffers 4 256k;
        proxy_busy_buffers_size 256k;
        proxy_max_temp_file_size 0;
        proxy_set_header X-Forwarded-Proto $scheme; 
        proxy_pass http://127.0.0.1:8008;
    }
}

upstream dashboard {
    server 127.0.0.1:8008;
    keepalive 512;
}

重新加載nginx服務

 sudo systemctl restart nginx

五、配置面板

1、通過域名訪問你的面板

2、登錄管理後台修改密碼 初始賬號密碼都是 admin


六、添加機器

1、複製安裝命令

2、安裝Agent

3、之後就可以在前台看見這個機器了

4、可以添加更多的機器

將複製的指令在其他機器上執行就可以實現監控其他的機器的狀態(只需要執行命令即可不需要再次安裝面板端)

七、最終效果