Share Local Site
Expose a local development server to the internet so anyone can access it via a public URL. No deployment needed.
When to use
- - Demo a work-in-progress site to a client or colleague
- Test a local site on a mobile device
- Share localhost for pair programming or review
- Quick external access without deploying
Methods comparison
| Method | Signup | Install | Stability | Best for |
|---|
| localhost.run | No | No | ⭐⭐ | Quickest start. Zero setup, perfect for first-time use |
| ngrok |
Yes | Yes | ⭐⭐⭐⭐ | Most stable. Dashboard, multi-tunnel, longer sessions |
|
cloudflared | No | Yes | ⭐⭐⭐ | Already installed; quick tunnels |
Quick start
localhost.run (zero-install, fastest to start)
Nothing to install, nothing to sign up for. Just run:
CODEBLOCK0
Look for the URL in the output (e.g. https://xxxxx.lhr.life). Share it immediately.
ngrok (most stable, recommended for longer sessions)
CODEBLOCK1
Get the public URL:
CODEBLOCK2
Web dashboard: http://127.0.0.1:4040
cloudflared
CODEBLOCK3
Pre-send checklist
Before sharing any tunnel URL, always verify:
- 1. Confirm the tunnel points to the correct port:
CODEBLOCK4
- 2. Verify the page loads correctly:
curl -sI <TUNNEL_URL> # check HTTP 200
curl -s <TUNNEL_URL> | grep -i '<title>' # confirm correct site
Watch for:
Invalid Host header, wrong project, blank page, 502.
- 3. Only send the URL after both checks pass.
Multiple tunnels (ngrok)
ngrok free tier supports up to 3 simultaneous tunnels. Run each in a separate terminal or tmux session:
CODEBLOCK6
List all active tunnels:
CODEBLOCK7
Framework-specific fixes
Vue CLI: "Invalid Host header"
Vue CLI's webpack-dev-server blocks non-localhost hosts by default.
Vue CLI 2/3 (webpack-dev-server v3):
CODEBLOCK8
Vue CLI 5+ (webpack-dev-server v4+):
CODEBLOCK9
Vite / Next.js / Nuxt: No config needed — tunnels work out of the box.
Create React App
CODEBLOCK10
Or in .env:
CODEBLOCK11
FAQ
Q: Do I need to restart the tunnel after code changes?
No. The tunnel just forwards traffic. Hot reload works normally — just refresh the page.
Q: How long does the URL last?
As long as the tunnel process is running. Close it and the URL dies.
Q: Can multiple people access the same URL?
Yes. Share the URL with anyone — it's a public endpoint.
Q: ngrok says "too many tunnels"?
Free tier allows 3 tunnels. Close unused ones or upgrade.
Recommended: pair with persistent-process
OpenClaw's exec sessions have automatic cleanup — idle timeout, context compaction, or gateway restart will silently kill any background process, including your tunnel. Your client is mid-demo and the URL just stops working.
To prevent this, install the openclaw-tmux-persistent-process skill. It runs your tunnel inside a tmux session that is completely independent of OpenClaw's exec lifecycle:
CODEBLOCK12
With both skills installed, tell your agent: "share port 3000 with tmux so it stays up" — it will start the tunnel in a persistent tmux session that survives gateway restarts.
Troubleshooting
| Problem | Fix |
|---|
| Invalid Host header | See framework-specific fixes above |
| ngrok token invalid |
Re-copy from dashboard.ngrok.com |
| localhost.run hangs | Switch to ngrok |
| Blank page / 502 | Make sure your local dev server is running |
| Wrong project showing | Check
curl localhost:4040/api/tunnels for port mapping |
| cloudflared 404 | Quick tunnels can be flaky — switch to ngrok |
分享本地站点
将本地开发服务器暴露到互联网,任何人都可以通过公共URL访问。无需部署。
使用场景
- - 向客户或同事演示正在开发中的站点
- 在移动设备上测试本地站点
- 为结对编程或代码审查分享本地主机
- 无需部署即可快速实现外部访问
方法对比
| 方法 | 注册 | 安装 | 稳定性 | 最佳适用场景 |
|---|
| localhost.run | 否 | 否 | ⭐⭐ | 启动最快。 零配置,非常适合首次使用 |
| ngrok |
是 | 是 | ⭐⭐⭐⭐ | 最稳定。提供仪表盘、多隧道、更长会话时长 |
|
cloudflared | 否 | 是 | ⭐⭐⭐ | 已安装时使用;快速建立隧道 |
快速开始
localhost.run(零安装,启动最快)
无需安装任何东西,也无需注册。只需运行:
bash
ssh -o StrictHostKeyChecking=no -R 80:localhost:3000 nokey@localhost.run
在输出中查找URL(例如 https://xxxxx.lhr.life)。可立即分享。
ngrok(最稳定,推荐用于较长会话)
bash
仅首次使用
brew install ngrok # 或:npm i -g ngrok,或从ngrok.com下载
ngrok config add-authtoken YOUR_TOKEN # 从dashboard.ngrok.com获取令牌
启动隧道
ngrok http 3000 # 将3000替换为你的端口号
获取公共URL:
bash
curl -s http://127.0.0.1:4040/api/tunnels | jq -r .tunnels[0].public_url
Web仪表盘:http://127.0.0.1:4040
cloudflared
bash
brew install cloudflared # 仅首次使用
cloudflared tunnel --url http://localhost:3000
发送前检查清单
在分享任何隧道URL之前,务必确认:
- 1. 确认隧道指向正确的端口:
bash
curl -s http://localhost:4040/api/tunnels | python3 -c
import sys,json; d=json.load(sys.stdin)
for t in d[tunnels]:
print(t[config][addr], t[public_url])
- 2. 验证页面正确加载:
bash
curl -sI
# 检查HTTP 200
curl -s | grep -i # 确认正确的站点
注意检查:Invalid Host header、错误的项目、空白页面、502错误。
- 3. 两项检查均通过后再发送URL。
多隧道(ngrok)
ngrok免费版支持最多3个同时运行的隧道。在每个独立的终端或tmux会话中运行:
bash
终端1:前端在端口5173
ngrok http 5173
终端2:后端在端口3001
ngrok http 3001
列出所有活跃隧道:
bash
curl -s http://localhost:4040/api/tunnels | python3 -c
import sys,json; d=json.load(sys.stdin)
for t in d[tunnels]:
print(f\{t[name]:20s} {t[config][addr]:30s} {t[public_url]}\)
特定框架的修复
Vue CLI:Invalid Host header
Vue CLI的webpack-dev-server默认阻止非本地主机的访问。
Vue CLI 2/3(webpack-dev-server v3):
js
// vue.config.js
module.exports = {
devServer: { disableHostCheck: true }
}
Vue CLI 5+(webpack-dev-server v4+):
js
// vue.config.js
module.exports = {
devServer: { allowedHosts: all }
}
Vite / Next.js / Nuxt: 无需配置——隧道开箱即用。
Create React App
bash
DANGEROUSLYDISABLEHOST_CHECK=true npm start
或者在 .env 文件中:
DANGEROUSLYDISABLEHOST_CHECK=true
常见问题
问:代码修改后需要重启隧道吗?
不需要。隧道仅负责转发流量。热重载正常工作——只需刷新页面即可。
问:URL有效期多长?
只要隧道进程在运行就有效。关闭进程后URL即失效。
问:多个人可以同时访问同一个URL吗?
可以。将URL分享给任何人即可——这是一个公共端点。
问:ngrok提示too many tunnels?
免费版允许3个隧道。关闭未使用的隧道或升级版本。
推荐:配合持久化进程使用
OpenClaw的exec会话具有自动清理机制——空闲超时、上下文压缩或网关重启都会静默终止后台进程,包括你的隧道。当你的客户正在看演示时,URL突然无法访问了。
为防止这种情况,请安装openclaw-tmux-persistent-process技能。它会在完全独立于OpenClaw exec生命周期的tmux会话中运行你的隧道:
bash
clawhub install openclaw-tmux-persistent-process
安装这两个技能后,告诉你的代理:使用tmux分享端口3000以保持持久运行——它将在持久化的tmux会话中启动隧道,即使网关重启也不会中断。
故障排除
| 问题 | 解决方法 |
|---|
| Invalid Host header | 参见上方特定框架的修复 |
| ngrok令牌无效 |
从dashboard.ngrok.com重新复制 |
| localhost.run卡住 | 切换到ngrok |
| 空白页面/502错误 | 确保本地开发服务器正在运行 |
| 显示错误的项目 | 检查 curl localhost:4040/api/tunnels 的端口映射 |
| cloudflared 404错误 | 快速隧道可能不稳定——切换到ngrok |