Nezha-zero 完整部署教程(Debian + NGINX + Cloudflare 单端口 gRPC)
注意:全文所有
nezha.example.com 请全部替换为你的真实域名。

前置准备

  1. Debian 服务器

  2. 域名 A 记录指向服务器公网 IP

  3. Cloudflare 账号


第一步:安装官方最新 NGINX

1
2
3
4
5
6
7
apt update
apt install -y curl gnupg2 ca-certificates lsb-release debian-archive-keyring
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian $(lsb_release -cs) nginx" | tee /etc/apt/sources.list.d/nginx.list
apt update
apt install -y nginx
nginx -v

第二步:安装 Nezha-zero Dashboard

1
curl -L https://ba.sh/naza -o naza.sh && chmod +x naza.sh && ./naza.sh

参数选择:

  • 安装方式:Docker

  • OAuth:n(需要使用OAuth请参考结尾)

  • 密码登录:y(设置强密码)

  • 站点访问端口:10086

  • Agent RPC 端口:10086(必须相同)
    验证:

1
2
docker ps | grep dashboard
curl -I http://127.0.0.1:10086

第三步:安装证书 + 配置 Nginx(注意换成你的域名)

1
2
apt install -y certbot python3-certbot-nginx
certbot --nginx -d nezha.example.com

输入邮箱回车 y回车 y回车
创建配置文件:(注意换成你的域名)

1
nano /etc/nginx/conf.d/nezha.example.com.conf

粘贴以下内容(把所有 nezha.example.com 替换为你的域名):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
server {
listen 80;
listen [::]:80;
server_name nezha.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name nezha.example.com;
ssl_certificate /etc/letsencrypt/live/nezha.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/nezha.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
underscores_in_headers on;
location ^~ /proto.NezhaService/ {
grpc_pass grpc://127.0.0.1:10086;
grpc_set_header Host $host;
grpc_set_header nz-realip $http_cf_connecting_ip;
grpc_set_header client_secret $http_client_secret;
grpc_set_header client_uuid $http_client_uuid;
client_body_timeout 3600s;
grpc_read_timeout 3600s;
grpc_send_timeout 3600s;
grpc_socket_keepalive on;
client_max_body_size 10m;
grpc_buffer_size 4m;
}
location / {
proxy_pass http://127.0.0.1:10086;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $http_cf_connecting_ip;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_http_version 1.1;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
}

ctrl+o保存 回车 ctrl+x退出

启用配置:

1
2
3
4
5
rm -f /etc/nginx/conf.d/default.conf
nginx -t
systemctl stop nginx
pkill -9 nginx
systemctl start nginx

第四步:配置 Dashboard

  1. 访问 https://nezha.example.com 登录

  2. 设置 → 「未接入 CDN 的面板服务器域名/IP」填写你的域名并保存

  3. 编辑配置:

1
nano /opt/nezha/dashboard/data/config.yaml

先删除已存在的 proxygrpcport 和 tls,然后在最上方添加:

1
2
proxygrpcport: 443
tls: true

ctrl+o保存 回车 ctrl+x退出
重启:

1
2
cd /opt/nezha/dashboard
docker compose down && docker compose up -d

第五步:Cloudflare 配置

  1. DNS 改为橙色云

  2. SSL/TLS → 完全(严格)

  3. 网络 → 开启 gRPC


后期维护

更新 NGINX

1
apt update && apt install nginx && nginx -t && systemctl restart nginx

更新 Nezha

1
./naza.sh restart_and_update

最终检查清单

  • [ ] 所有 nezha.example.com 已替换为真实域名

  • [ ] https://你的域名 可正常登录

  • [ ] config.yaml 中 proxygrpcport 和 tls 只出现一次

  • [ ] Cloudflare 已开启橙色云 + gRPC

  • [ ] Agent 可正常上线


使用GitHub登录

  1. 打开 https://github.com/settings/developers ,依次选择 “OAuth Apps” - “New OAuth App”。

  2. 填写以下需要的字段:
    Application name:应用名
    Homepage URL:面板访问地址,例如 https://nezha.example.com
    Authorization callback URL 面板的 Callback 地址,这里只检测前缀,所以可以填写
    https://nezha.example.com/oauth2/callback