Turn Your Own Machine Into a Public API Server (For Free) Using Cloudflare Tunnel
说明与用途
使用 Cloudflare Tunnel 将本地 API 暴露为公共服务器,无需端口转发。
问题
Expose a local API to the internet without port forwarding, firewall changes, or cloud deployment.
结果
Local FastAPI server is securely exposed to the internet via Cloudflare Tunnel without opening inbound ports or changing firewall settings.
工作流
- Install cloudflared via brew
- Log in with cloudflared tunnel login
- Create a tunnel with cloudflared tunnel create my-tunnel
- (Optional) Map a domain with cloudflared tunnel route dns my-tunnel api.yourwebsite.com
- Create ~/.cloudflared/config.yml with tunnel ID, credentials file, and ingress rules
- Run the tunnel with cloudflared tunnel run my-tunnel
- (Optional) Use launchctl on macOS to keep the tunnel alive
证据
cloudflared connects out to Cloudflare, so your router and firewall stay closed.
No domain? For quick tests, cloudflared tunnel --url http://localhost:8000 gives you a temporary trycloudflare.com address instead.
- 记录日期: 2026-10-25T04:11:09.967Z