updated: 2026-11-22
落地:2026-11-22 服务器:aliyun = 119.23.65.115(CentOS Stream 10 / systemd 257 / 宝塔 nginx 1.30.5,已占 80+443) 上游仓库:https://github.com/WNLUO/dsh-mobile-server(MIT,Rust,纯转发) 相关:[[服务器清单]] · [[阿里云服务器]](那台是 aliyun2=47.109.158.218,别搞混)
dsh-relay 只是中转/relay,不是桌面端、也不是手机 App:
手机 App ──HTTPS/WSS──> nginx(443) ──> dsh-relay(127.0.0.1:18788) <──WSS 出站隧道── DSH 桌面端(本机)
dsh-mobile-plugin)主动出站连 https://<中转域名>/tunnel,所以家里/公司不需要公网 IP、不需要端口映射。TUNNEL_REGISTER_SECRET 后,隧道注册必须带同一把密钥。https://ai-hub-de-1.wnluo.com(作者自己维护)。自建 = 把手机到桌面这跳换成自己的机器。代价(先想清楚再自建)
.p8;用自己 Apple 账号重签的 App 会被苹果拒收。uname -m # 只支持 x86_64 / aarch64(官方只发这两个架构的静态 musl 二进制)
systemctl --version # 必须 systemd
command -v curl sha256sum
ss -lntp | grep 18788 # 端口要空着
官方安装脚本的真实路径是 server/relay/rust/deploy/install-binary.sh(README 里那个裸 install-binary.sh 是 404):
# GitHub 可达的机器上
curl -fsSL https://raw.githubusercontent.com/WNLUO/dsh-mobile-server/main/server/relay/rust/deploy/install-binary.sh -o /tmp/install-binary.sh
sh /tmp/install-binary.sh
⚠️ 国内服务器直连 GitHub 基本超时(本机实测
raw.githubusercontent.com15s 超时 / curl 000)。 实测可行的替代:本地先下好脚本,再推到服务器执行——scp /path/install-binary.sh aliyun:/root/ && ssh aliyun 'sh /root/install-binary.sh'。 脚本自己拉清单和二进制时用的是https://dsh-hub.wnluo.com/relay-updates(国内镜像在前),这条路是通的。
脚本做的事(知道这些才不会"装完不知道怎么改"):
| 产物 | 说明 |
|---|---|
/opt/dsh-relay/dsh-relay |
静态二进制;dsh-relay --version 可验 |
/etc/systemd/system/dsh-relay.service |
Environment=HOST=127.0.0.1 PORT=18788,Restart=always,日志 append 到 /opt/dsh-relay/logs/relay.log |
/etc/dsh-relay-update.env |
SELF_UPDATE=1 + SELF_UPDATE_SOURCE=...dsh-hub...,...raw.githubusercontent...(已存在则不覆盖) |
/etc/dsh-relay-console.env |
可选,脚本不写;存在就会被加载 |
| 自检 | curl http://127.0.0.1:18788/healthz → ok |
脚本刻意不做:不配 TLS、不改 nginx、不开防火墙。这些是下一步。
systemctl enable --now dsh-relay
systemctl is-active dsh-relay
/opt/dsh-relay/dsh-relay --version
curl -s http://127.0.0.1:18788/healthz; echo
tail -n 5 /opt/dsh-relay/logs/relay.log
服务器侧变量:TUNNEL_REGISTER_SECRET。用 drop-in 写,别改主 unit(升级脚本可能动它):
mkdir -p /etc/systemd/system/dsh-relay.service.d
# 生成一把:openssl rand -hex 24
printf '[Service]\nEnvironment=TUNNEL_REGISTER_SECRET=%s\n' "$(openssl rand -hex 24)" \
> /etc/systemd/system/dsh-relay.service.d/secret.conf
chmod 600 /etc/systemd/system/dsh-relay.service.d/secret.conf
systemctl daemon-reload && systemctl restart dsh-relay
systemctl show -p Environment dsh-relay | tr ' ' '\n' | grep TUNNEL_REGISTER_SECRET # 确认注入
~/.dsh/relay.json 的 registerSecret(见 §2),两边不一致 → 隧道被"注册超时"踢掉。/etc/systemd/system/dsh-relay.service.d/secret.conf(600)、本机 ~/.dsh/relay.json:registerSecret。别提交进 git。宝塔的 vhost 目录会被 http 块自动 include:/www/server/panel/vhost/nginx/<域名>.conf。整份内容(可直接复制改域名):
server {
listen 80;
server_name relay.example.com;
root /www/wwwroot/dsh-relay-ssl; # acme http-01 webroot,不必有站点内容
location /.well-known/acme-challenge/ {
root /www/wwwroot/dsh-relay-ssl;
try_files $uri =404;
}
location / { return 301 https://$host$request_uri; } # 其余一律升级到 https
}
server {
listen 443 ssl;
http2 on;
server_name relay.example.com;
ssl_certificate /www/server/panel/vhost/cert/relay.example.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/relay.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache shared:SSL:10m;
client_max_body_size 100m;
location / {
proxy_pass http://127.0.0.1:18788;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; # /tunnel 是 WebSocket,这两行不能少
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off; # SSE/长连接必须关缓冲
proxy_request_buffering off;
proxy_read_timeout 3600s; # 隧道空闲也要能挂着
proxy_send_timeout 3600s;
}
}
证书(acme.sh,用 webroot 模式,不碰 Nginx 配置):
# 安装(GitHub 不通时走 gitee 镜像)
curl -fsSL --max-time 40 https://gitee.com/neilpang/acme.sh/raw/master/acme.sh -o /tmp/acme.sh
cd /tmp && sh ./acme.sh --install # ⚠️ 必须 cd 进去再执行,直接 sh /tmp/acme.sh --install 会报 cp: cannot stat 'acme.sh'
mkdir -p /www/wwwroot/dsh-relay-ssl/.well-known/acme-challenge
chown -R www:www /www/wwwroot/dsh-relay-ssl
# 签发(一次写多个 -d 就是一张多域名 SAN 证书)
/root/.acme.sh/acme.sh --issue -d relay.example.com -w /www/wwwroot/dsh-relay-ssl --server letsencrypt
# 装到宝塔证书目录 + reload
mkdir -p /www/server/panel/vhost/cert/relay.example.com
/root/.acme.sh/acme.sh --install-cert -d relay.example.com --ecc \
--key-file /www/server/panel/vhost/cert/relay.example.com/privkey.pem \
--fullchain-file /www/server/panel/vhost/cert/relay.example.com/fullchain.pem \
--reloadcmd "nginx -s reload"
48 3,9,15,21 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh",一般不用管。--standalone(要 80 空闲)。没有域名时的应急入口:sslip.io 把 IP 写进域名就能解析,例如 119-23-65-115.sslip.io → 119.23.65.115,可直接签发证书;实测未被拦。作为备用 server_name 挂在同一张证书里很省事(本机就是 relay.zilanlife.com + 119-23-65-115.sslip.io 一张证书)。
nginx -t && nginx -s reload
curl -s -o /dev/null -w '%{http_code}\n' https://relay.example.com/healthz # 期望 200
curl -s -i -N -H 'Connection: Upgrade' -H 'Upgrade: websocket' \
-H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' \
https://relay.example.com/tunnel | head -3 # 期望 HTTP/1.1 101
18788 只绑 127.0.0.1,不要在安全组里开——公网直连裸 relay 没 TLS 也没意义。server_name 分流。控制面是本机 loopback(端口 = DSH GUI 端口,默认 3080):
| 接口 | 用途 |
|---|---|
GET /api/relay/status |
看 relayUrl、tunnel.state、tunnel.error |
GET /api/relay/panel |
手机面板页 |
POST /api/relay/config |
改配置(localOnly) |
curl -s -X POST http://127.0.0.1:3080/api/relay/config \
-H 'Content-Type: application/json' \
-d '{"relayUrl":"https://relay.example.com","relayUrls":["https://relay.example.com"],"registerSecret":"<密钥>"}'
# 验证
curl -s http://127.0.0.1:3080/api/relay/status | python3 -c \
'import json,sys;s=json.load(sys.stdin);print(s["relayUrl"],s["tunnel"]["state"],s["tunnel"].get("error"))'
# 期望: https://relay.example.com connected None
⚠️ 面板已经不再提供「注册密钥」输入框。所以只要中转开了
TUNNEL_REGISTER_SECRET,纯 GUI 改地址会连不上,必须走上面这条 API(或者直接编辑~/.dsh/relay.json的registerSecret)。改完不用重启 DSH。
~/.dsh/relay.json 里相关字段:relayUrl / relayUrls(列表优先)/ registerSecret / enabled / lanEnabled / lanPort:18787 / pairingPolicy:"code"。这个文件含 instanceId、pairingTicket、lanSecret、p2p 私钥、controlToken,别外发。
回滚到官方中转(一条命令):
curl -s -X POST http://127.0.0.1:3080/api/relay/config -H 'Content-Type: application/json' \
-d '{"relayUrl":"https://ai-hub-de-1.wnluo.com","relayUrls":["https://ai-hub-de-1.wnluo.com"],"registerSecret":""}'
http://127.0.0.1:3080/api/relay/panel)→ 重新生成配对码 → 出二维码/配对码。pairingPolicy:"code" = 输对配对码即放行;"deny" = 全部拒绝;另有 approval 流程(headless 宿主没有弹窗面)。devices.count),旧设备在面板里可删。ssh aliyun
systemctl status dsh-relay --no-pager
tail -f /opt/dsh-relay/logs/relay.log # 看隧道连没连上
curl -s http://127.0.0.1:18788/healthz # 期望 ok
curl -s https://relay.zilanlife.com/healthz # 公网链路
systemctl restart dsh-relay # 改完 secret.conf / 换源之后
/etc/dsh-relay-update.env 里 SELF_UPDATE=1,每 24h 查一次 latest.json;不想自动升就删掉 SELF_UPDATE 或整个文件。想换源就改 SELF_UPDATE_SOURCE(逗号分隔,按序尝试;自己的静态目录要能取到 latest.json)。/opt/dsh-relay/dsh-relay --version。systemctl show -p Environment dsh-relay、ss -lntp | grep 18788。| 现象 | 原因 / 处置 |
|---|---|
/tunnel 返回 101,但 relay 日志 tunnel registration timeout, closing |
两边密钥不一致或插件侧没填 registerSecret。日志里 unregistered so far=N 就是这个 |
日志出现 tunnel connected → mirror stored instance=<id> ... |
注册成功,通道已通(这是"切好了"的判据) |
服务器本机 healthz 200,公网 502/504 |
nginx 没 reload、vhost 没被 include、或 server_name 不匹配;nginx -t 先过 |
| 公网 443 连不上但 80 正常 | 证书路径错 / 证书过期 → 重跑 --install-cert + nginx -s reload |
curl raw.githubusercontent.com 超时 000 |
国内常态。装脚本/证:脚本从本机推,acme 走 gitee 镜像 |
ssh_cluster / dsh_ssh 对该机报 exit code 35 |
该 host 用 bash ssh aliyun 正常,工具通道会挂;直接用 bash ssh |
| 手机连不上但桌面端显示 connected | 先 https://域名/healthz,再看插件 /api/relay/status 的 tunnel.state 与 tunnel.error,最后看 relay.log |
| 手机必须走中转、内网也慢 | 插件会优先局域网直连(lanPort:18787、lanEnabled:true),中转只兜外网 |
A. 服务器换一台
healthz ok。nginx -t),放行 80/443。systemctl disable --now dsh-relay(别让它继续挂着)。B. 换域名
server_name 加新域名(旧的可一并留着)。--issue -d new.example.com -d old.example.com ...,再 --install-cert。POST /api/relay/config 改 relayUrl。C. 换电脑部署(同一中转)
dsh-mobile-plugin(~/.dsh/profiles/<profile>)。POST /api/relay/config 写 relayUrl + registerSecret(或直接改 ~/.dsh/relay.json),确认 tunnel.state=connected。| 项 | 值 |
|---|---|
| 服务器 | aliyun 119.23.65.115(CentOS Stream 10,systemd 257,SELinux disabled) |
| relay 版本 | 0.1.30(x86_64 静态 musl,sha256 b861df5d…a8) |
| 进程 | dsh-relay 服务,127.0.0.1:18788,日志 /opt/dsh-relay/logs/relay.log |
| 公网入口 | https://relay.zilanlife.com(备用 https://119-23-65-115.sslip.io) |
| 证书 | Let's Encrypt ECC,SAN={relay.zilanlife.com, 119-23-65-115.sslip.io},到期 2027-02-20,目录 /www/server/panel/vhost/cert/relay.zilanlife.com/ |
| vhost | /www/server/panel/vhost/nginx/relay.zilanlife.com.conf(旧的 sslip 专用配置留作 .bak-*) |
| 密钥 | 服务器 /etc/systemd/system/dsh-relay.service.d/secret.conf(600);桌面端 ~/.dsh/relay.json:registerSecret |
| 桌面端 | dsh-mobile-plugin 0.5.94,relayUrl=https://relay.zilanlife.com,tunnel.state=connected |
| 资源占用 | 二进制 9.0MiB(含 .previous 约 18MiB),稳态 ~96MiB,日志上限 80MiB |
| 同架构参考 | 作者在成都阿里云也自建了一台:cd-ai-hub.wnluo.com / 47.108.201.215(Alpine + OpenRC) |