宝塔面板部署哪吒探针TLS单域名上线教程教程
📋 前期准备
- 一台服务器:用于部署哪吒探针,服务器配置不建议太低。
- 一个域名:例如
nezha.domain.com,CloudflareA 记录解析到你的服务器公网IP,开启小黄云。 - Cloudflare:开启gRPC和WebSockets,申请个15年的证书留着备用。
- 安装宝塔面板:确保你的服务器已安装宝塔面板并安装Docker。
步骤一:安装哪吒探针
1.1 通过Docker安装
1.宝塔面板打开Docker页面,点击容器编排。
2.点击添加容器编排,名称随便,compose填写内容如下,然后点击确定开始部署。
services:
dashboard:
image: ghcr.io/nezhahq/nezha
container_name: nezha-dashboard
restart: always
volumes:
- ./data:/dashboard/data
ports:
- "127.0.0.1:8008:8008"1.2 配置Nginx反向代理
1.宝塔面板点击网站页面,点击反向代理,添加反代。
2.填写你Cloudflare解析此服务器IP的域名,目标选项选择URL地址输入http://127.0.0.1:8008,点击确定。
3.部署你Cloudflare申请的15年证书。点击反代的设置-配置文件,填入以下内容。
server {
listen 443 ssl ;
listen [::]:443 ssl ;
http2 on;
# http2 on; # 对于 Nginx 1.28.0,建议使用上面的 listen 指令方式
server_name 你的域名;
ssl_certificate /你的公钥文件位置.pem;
ssl_certificate_key /你的私钥文件位置.pem;
ssl_stapling off; # 临时禁用,解决证书链问题
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1.2 TLSv1.3;
underscores_in_headers on;
set_real_ip_from 0.0.0.0/0;
real_ip_header CF-Connecting-IP;
# grpc 相关
location ^~ /proto.NezhaService/ {
grpc_set_header Host $host;
grpc_set_header nz-realip $http_CF_Connecting_IP;
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 $http_cf_connecting_ip;
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 $http_cf_connecting_ip;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_buffer_size 128k;
proxy_buffers 4 128k;
proxy_busy_buffers_size 256k;
proxy_max_temp_file_size 0;
proxy_pass http://127.0.0.1:8008;
}
}
upstream dashboard {
server 127.0.0.1:8008;
keepalive 512;
}1.3 哪吒探针后台设置
1.访问反代设置的域名,登录你的哪吒后台。
2.打开系统设置,配置Agent对接地址为你的域名:443端口,勾选Agent使用TLS连接。
3.前端真实IP请求头和Agent真实IP请求头均填写nz-realip。