Dashboard 反向代理配置
哪吒监控 V2 不区分 Dashboard Web 和 Agent gRPC 端口,访问与通信均可通过默认的 8008 端口。
Nginx 配置示例
以下是使用 Nginx 配置反向代理的示例:
nginx
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
# http2 on; # Nginx > 1.25.1,请注释上面两行,启用此行
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;
set_real_ip_from 0.0.0.0/0; # 替换为你的 CDN 回源 IP 地址段
real_ip_header CF-Connecting-IP; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
# 如果你使用nginx作为最外层,把上面两行注释掉
# grpc 相关
location ^~ /proto.NezhaService/ {
grpc_set_header Host $host;
grpc_set_header nz-realip $http_CF_Connecting_IP; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
# grpc_set_header nz-realip $remote_addr; # 如果你使用nginx作为最外层,就把上面一行注释掉,启用此行
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 $http_host;
proxy_set_header nz-realip $http_cf_connecting_ip; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
# proxy_set_header nz-realip $remote_addr; # 如果你使用nginx作为最外层,就把上面一行注释掉,启用此行
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 $http_host;
proxy_set_header nz-realip $http_cf_connecting_ip; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
# proxy_set_header nz-realip $remote_addr; # 如果你使用nginx作为最外层,就把上面一行注释掉,启用此行
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; # 如果你使用nginx作为最外层,就启用此行避免无法正确读取访问的协议
proxy_pass http://127.0.0.1:8008;
}
}
upstream dashboard {
server 127.0.0.1:8008;
keepalive 512;
}Caddy 配置示例
以下是使用 Caddy 配置反向代理的示例:
caddy
dashboard.example.com {
@grpcProto {
path /proto.NezhaService/*
}
reverse_proxy @grpcProto {
header_up Host {host}
header_up nz-realip {http.CF-Connecting-IP} # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
# header_up nz-realip {remote_host} # 如果你使用caddy作为最外层,就把上面一行注释掉,启用此行
transport http {
versions h2c
read_buffer 4096
}
to localhost:8008
}
reverse_proxy {
header_up Host {hostport}
header_up nz-realip {http.CF-Connecting-IP} # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
# header_up nz-realip {remote_host} # 如果你使用caddy作为最外层,就把上面一行注释掉,启用此行
transport http {
read_buffer 16384
}
to localhost:8008
}
}配置注意事项
调整 Header
根据您使用的 CDN 服务商,替换CF-Connecting-IP和相关配置为您的 CDN 提供的私有 header。HTTPS 配置
确保 SSL 证书路径正确,并已正确配置域名解析。负载调整
根据服务器性能和访问需求,可调整keepalive和buffer设置。原样转发 Host(包括端口)和 Origin
从 v2.6.0 起,Dashboard 在密码登录时会检查浏览器请求的Origin是否与 Dashboard 收到的Host一致,主机名和端口都要相同;WebSocket 连接(实时数据、终端、文件管理)同样会比较这两个请求头。转发给 Dashboard 的Host必须和浏览器地址栏中的域名、端口一致,Origin保持浏览器发送的原值:- Nginx 使用
proxy_set_header Host $http_host;。$host不带端口,通过非标准端口(如https://dashboard.example.com:8443)访问时会导致登录失败;不写Host时 Nginx 默认发送proxy_pass中的地址(如127.0.0.1:8008),同样会失败。 - 上游为 HTTP 时(如本例的
to localhost:8008),Caddy 默认原样转发Host;需要显式设置时使用{hostport},不要用不带端口的{host},也不要改成上游地址。上游为 HTTPS 时,Caddy 2.11 起默认把Host设为上游地址,这时需要显式写header_up Host {hostport}。 - 不要改写
Origin请求头。在登录请求的位置改写会让该项检查失效;在 WebSocket 位置改写会让 WebSocket 的来源检查失去意义,或在与 Host 不一致时导致连接失败。 - v2.8.3 及以上版本在登录和 WebSocket 检查中把省略的端口与对应协议的默认端口视为等价(
https为443,http为80),例如浏览器访问https://dashboard.example.com时,Host为dashboard.example.com:443也能正常使用。v2.6.0 至 v2.8.2 要求完全一致,所以仍建议原样转发 Host,不要额外加上默认端口。
如果升级后正确的密码也提示错误,请参考 登录常见问题。
- Nginx 使用