先生成几个密钥,后面会用到:
openssl rand -hex 32 # TURN_SECRET(coturn 与 signaling 共用) openssl rand -hex 32 # BACKEND_SECRET(signaling 与 Nextcloud 共用) openssl rand -hex 32 # HASHKEY openssl rand -hex 16 # BLOCKKEY openssl rand -hex 16 # INTERNALSECRET
在nextcloud的出口的vps上安装:apt install coturn编辑
/etc/turnserver.conf:listening-port=3478 fingerprint use-auth-secret static-auth-secret=<TURN_SECRET> realm=turn.example.com total-quota=100 stale-nonce no-multicast-peers # 如果在 NAT 后面: # external-ip=公网IP/内网IP
然后 systemctl enable --now coturnnextcloud的机器上安装 NATS ,只是signaling连接该服务。
apt install nats-server systemctl enable --now nats-server默认监听
127.0.0.1:4222,保持默认即可。如果你的源里没有该包,可以从 nats-io/nats-server 的 GitHub Releases 下载二进制文件。vps上安装并配置 Janus
bashapt install janus(a)
/etc/janus/janus.jcfg,在nat段设置:nat: { stun_server = "turn.example.com" stun_port = 3478 nice_debug = false full_trickle = true }如需限制 RTP 端口范围,在
media段设置rtp_port_range = "20000-40000"。(b)
/etc/janus/janus.transport.websockets.jcfg,只启用本地 WebSocket:general: { ws = true ws_ip = "127.0.0.1" ws_port = 8188 wss = false }(c) 禁用不需要的传输方式(HTTP/REST)。在
/etc/janus/janus.transport.http.jcfg中把general.http设为false;若没有这个文件,保持默认也可以,但不要把 8088/7088 暴露到公网。(d) 确认
janus.plugin.videoroom.jcfg存在。如果配置目录里只有.sample后缀的文件,复制一份去掉后缀。然后启动:bashsystemctl enable --now janus4. nextcloud的机器上安装 nextcloud-spreed-signaling
bash
apt install git make git clone https://github.com/strukturag/nextcloud-spreed-signaling.git cd nextcloud-spreed-signaling make build install -m 755 bin/signaling /usr/local/bin/signaling useradd --system --no-create-home --shell /usr/sbin/nologin signaling mkdir -p /etc/signaling创建
/etc/signaling/server.conf:ini[http] listen = 127.0.0.1:8080 [app] debug = false # 信令前面有反代,需要信任它 trustedproxies = 127.0.0.1 [sessions] hashkey = <HASHKEY> blockkey = <BLOCKKEY> [clients] internalsecret = <INTERNALSECRET> [backend] backends = backend-1 allowall = false timeout = 10 connectionsperhost = 8 [backend-1] url = https://你的域名:8310 #注意需要和你的nextcloud机器上的端口一致 secret = <BACKEND_SECRET> # 如果 Nextcloud 用的是自签名证书,才需要加这一行: # skipverify = true [nats] url = nats://127.0.0.1:4222 [mcu] type = janus url = ws://127.0.0.1:8188 [turn] apikey = 随便填一个字符串 secret = <TURN_SECRET> servers = turn:turn.example.com:3478?transport=udp,turn:turn.example.com:3478?transport=tcpbashchown -R root:signaling /etc/signaling chmod 640 /etc/signaling/server.conf创建 systemd 服务
/etc/systemd/system/signaling.service:ini[Unit] Description=Nextcloud Talk signaling server After=network.target nats-server.service janus.service Wants=nats-server.service janus.service [Service] Type=simple User=signaling Group=signaling ExecStart=/usr/local/bin/signaling --config /etc/signaling/server.conf Restart=on-failure [Install] WantedBy=multi-user.targetbashsystemctl daemon-reload systemctl enable --now signaling journalctl -u signaling -f # 查看日志是否有报错
然后再nextclou的机器上:反向代理(nginx 示例)
在
signal.example.com的 HTTPS server 块里加入:nginxlocation /standalone-signaling/ { proxy_pass http://127.0.0.1:8080/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; 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_read_timeout 86400s; } location /standalone-signaling/api/v1/welcome { proxy_pass http://127.0.0.1:8080/api/v1/welcome; expires -1; }重载 nginx 后测试:
bashcurl https://signal.example.com/standalone-signaling/api/v1/welcome应返回类似
{"nextcloud-spreed-signaling":"Welcome",...}的 JSON。
在 Nextcloud 中配置
以管理员身份进入 管理设置 → Talk:
- 高性能后端
- URL:
https://signal.example.com/standalone-signaling/- 共享密钥:
<BACKEND_SECRET>- 如果证书是自签名的,勾选"验证 TLS 证书"相关选项,取消校验。
- STUN 服务器:
turn.example.com:3478- TURN 服务器:
turn.example.com:3478,密钥填<TURN_SECRET>,协议选"UDP 和 TCP"。VPS ↔ nextcloud部署的机器:SSH 隧道转发 Janus 的 WebSocket
signaling 在nextcloud部署的机器,需要访问 VPS 上仅监听回环的 Janus。用一条受限的 SSH 隧道。
nextcloud部署的机器:
bashuseradd --system --create-home --shell /usr/sbin/nologin janus-tunnel sudo -u janus-tunnel ssh-keygen -t ed25519 -N "" -f /home/janus-tunnel/id_ed25519 cat /home/janus-tunnel/id_ed25519.pubVPS:
bashuseradd --create-home --shell /usr/sbin/nologin tunnel mkdir -p /home/tunnel/.ssh echo 'restrict,port-forwarding,permitopen="127.0.0.1:8188" <上一步的公钥内容>' > /home/tunnel/.ssh/authorized_keys chown -R tunnel:tunnel /home/tunnel/.ssh chmod 700 /home/tunnel/.ssh && chmod 600 /home/tunnel/.ssh/authorized_keysnextcloud部署的机器:
/etc/systemd/system/janus-tunnel.serviceini[Unit] Description=SSH tunnel to Janus on VPS After=network-online.target Wants=network-online.target [Service] User=janus-tunnel ExecStart=/usr/bin/ssh -N -L 127.0.0.1:8188:127.0.0.1:8188 \ -o ExitOnForwardFailure=yes -o ServerAliveInterval=15 -o ServerAliveCountMax=3 \ -o StrictHostKeyChecking=accept-new \ -i /home/janus-tunnel/id_ed25519 -p <VPS的SSH端口> tunnel@<vps的ip地址> Restart=always RestartSec=5 [Install] WantedBy=multi-user.targetbashsystemctl daemon-reload systemctl enable --now janus-tunnel ss -ltnp | grep 8188 # nextcloud部署的机器应看到 127.0.0.1:8188如果你的nextcloud部署的机器到 VPS 的 SSH 需要走特定路由(比如你网关上的策略路由),按你现有的方式处理即可;也可以改用网关 上开一个 dokodemo-door 转到 VPS 的 127.0.0.1:8188,但那样 signaling 的
mcu.url要改成指向网关地址,且这段是明文,只适合可信局域网。
/etc/hosts:
bashecho "127.0.0.1你的域名" >> /etc/hosts
listen 127.0.0.1:8310 ssl; # 本机回环,不带 PROXY 头
bashnginx -t && systemctl reload nginx