使用Tailscale Services暴露内网服务
背景
使用反代暴露了一些部署在homelab上的服务,使用caddy配合tailscale提供域名TLS证书。
类似gogs等服务原生支持子路径部署,可以通过lab.tailxxxx.ts.net/gogs正确访问,从而节省域名。
但类似homeassistant明确不支持子路径部署的服务则需要占用独立域名,
经过查阅,tailscale不支持类似ha.lab.tailxxxx.ts.net的子域证书发放,
只能通过创建一个名为ha的节点容器加入tailnet再部署反代曲线救国。
实现
就在容器视频上线的两年后,tailscale释放了全新services功能完美解决这一问题。
使用service必须绑定tagged nodes,可以检查ACL json是否开启,默认是注释掉的。
// Define the tags which can be applied to devices and by which users.
"tagOwners": {
"tag:server": ["autogroup:admin"],
},
登录tailscale面板,确认当前节点已经加入tag:server后找到Services - Define a Service
名称输入ha可用ha.tailxxxx.ts.net访问,Ports选443标准https,Service tags选刚创建的tag:server
来到节点终端执行
tailscale serve --service=svc:ha --https=443 http://127.0.0.1:8123
初次执行需要管理员在Services - ha - Hosts中放行,再次执行提示成功
Available within your tailnet:
https://ha.tailxxxx.ts.net/
|-- proxy http://127.0.0.1:8123
Serve started and running in the background.
To disable the proxy, run: tailscale serve --service=svc:ha --https=443 off
To remove config for the service, run: tailscale serve clear svc:ha
调试
services ha绿灯上线,但访问域名提示400 Bad requests使用docker logs -f ha检查日志发现
A request from a reverse proxy was received from 127.0.0.1, but your HTTP integration is not set-up for reverse proxies
HomeAssistant需要手动授权反代白名单,修改configuration.yaml后重启HA服务问题解决。
http:
use_x_forwarded_for: true
trusted_proxies:
- 127.0.0.1
- ::1
到此,域名ha.tailxxxx.ts.net已经能够被tailnet内的客户端访问,如需公网访问可使用funnel命令。
参考
A deep dive into using Tailscale with Docker - YouTube
Tailscale Services GA: App-aware connectivity with more control
Tailscale Services · Tailscale Docs
HTTP integration is not set-up for reverse proxies? - Configuration - Home Assistant Community

浙公网安备 33010602011771号