哪吒監控+cfcdn+ 反代grp端口
背景:
-
哪吒監控:感覺VPS線路不穩定,為了打消自己潛意識,希望量化延遲。
-
cfcdn:隱藏真實站點,保障小雞隱秘安全
-
反代grpc端口: 反代grpc到支持https(TLS)的端口,這樣dashboard與agent的grpc傳輸會開啟TLS安全傳輸。CF只支持443,這里反代grpc端口到443
具體步驟:
參考文檔里面有詳細步驟這里只列出一些關鍵點
安裝 Dashboard |官方文檔
Nezha Monitoring | 大數據最佳實踐
需要準備
-
GitHub oauth2賬號
-
cf上兩個域名
接入GitHub作為后臺管理員賬號
使用oauth2登錄極大的提高了自建應用的安全性,好評
安裝Dashboard
我是用docker compose 安裝
9080:dashboard端口
5555:dashboard與agent通信端口
services:dashboard:image: ghcr.io/naiba/nezha-dashboardrestart: alwayscontainer_name: nezhavolumes:- ./data:/dashboard/data- ./static-custom/static:/dashboard/resource/static/custom:ro- ./theme-custom/template:/dashboard/resource/template/theme-custom:ro- ./dashboard-custom/template:/dashboard/resource/template/dashboard-custom:roports:- 9080:80- 5555:5555
NG配置
反代Dashboard
https能力需NG提供,訪問路徑是:https://域名 -> NG:443 ->dashboaed 9080
一個是反代/
一個是反代理ws
一個反代terminal
location / {proxy_pass http://127.0.0.1:9080;proxy_set_header Host $http_host;proxy_set_header Upgrade $http_upgrade;}location ~ ^/(ws|terminal/.+)$ {proxy_pass http://127.0.0.1:9080;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "Upgrade";proxy_set_header Host $http_host;}tp_host;
}
SNI分流
-
Dashboard不支持
DOMAIN_PATH
,需獨占一個域名。使用xxxx.eu.org
-
dashboard與 agent grpc端口需要反代到443,也需要獨占一個域名。使用
data.xxxx.eu.org
兩個域名都監聽443,所以ng上配置域名SNI分流
創建 /etc/nginx/conf.d/sni.stream
配置。定義一個map,proxy_pass 帶給后端端口
9443:Dashboard
10443:data
map $ssl_preread_server_name $backend_name {xxxx.eu.org cf;data.xxxx.eu.org cf-cat;
}
upstream cf {server 127.0.0.1:9443;server [::1]:9443;
}upstream cf-data {server 127.0.0.1:10443;server [::1]:10443;
}server {listen 443 reuseport;listen [::]:443 reuseport;proxy_pass $backend_name;ssl_preread on;proxy_protocol on;
}
在 /etc/nginx/nginx.conf
中引入sni分流的stream
stream {log_format basic '$remote_addr [$time_local] ''$protocol $status $bytes_sent $bytes_received ''$session_time $ssl_preread_server_name';include /etc/nginx/conf.d/*.stream;
}
這樣就可以按照SNI域名分流到后端的Dashboard或者grpc了
反代grp端口到443
dashboard與agent grpc使用https更加安全,我因為使用CF,所以反代grpc端口到443,開啟TLS安全傳輸
官方文檔很詳細:反向代理 gRPC 端口(支持 Cloudflare CDN) | 哪吒監控
grpc默認就安全的?
grpc默認傳輸如果沒有TLS證書,抓包看看,TCP里面是明文的
看看agent的源碼
agent/cmd/agent/main.go at f882ca3498c0766784e31ba454bb09934a118fd3 · nezhahq/agent · GitHub
securityOption = grpc.WithTransportCredentials(insecure.NewCredentials())
沒有TL證書,默認grpc就是不安全
為什么使用CF的CDN
隱藏源站IP,而且CF CDN支持grpc
哪吒監控Agent按照
安裝 Agent | 哪吒監控