1.ngrok 官网下载安装
https://ngrok.com/
官网已经有说明,使用很简单
解压后,配置token
ngrok config add-authtoken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
执行代理
Home Assistant 内网地址为 192.168.2.9:8123
ngrok http 192.168.2.9:8123
会有以下信息
ngrok (Ctrl+C to quit)
Join us in the ngrok community @ https://ngrok.com/slack
Session Status online
Account xxxx@gmail.com (Plan: Free)
Version 3.0.6
Region Asia Pacific (ap)
Latency -
Web Interface http://127.0.0.1:4040
Forwarding https://a418-16-163-246-9.ap.ngrok.io -> http://192.168.2.9:8123
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
访问 https://a418-16-163-246-9.ap.ngrok.io 即可访问到内网 Home Assistant
这时候访问,会出现 400 Bad Request,需要配置Home Assistant
2.配置 Home Assistant 代理白名单
修改 configuration.yaml 文件,增加如下内容
http:
use_x_forwarded_for: true
trusted_proxies:
- 18.141.129.0/24
- 192.168.2.0/24
- 127.0.0.1
18.141.129.0/24 是ngrok服务器ip,下边为内网,现在就可以在外网访问了