This post documents how to use local hardware (Mac mini) combined with Cloudflare’s edge network to build a publicly accessible AI blog and backend service system—without opening any inbound ports on your router.
1. Infrastructure Cost & Component Selection#
Domain Registration
- Cost: Registering or transferring a domain to Cloudflare (e.g.,
frank-zhang.com) costs only$10.42/yr(wholesale price, no markup). - Advantage: Directly integrated into the Cloudflare ecosystem, simplifying DNSSEC and tunnel configuration.
Why Cloudflare?
- Generous Free Plan: For individual engineers, the free tier already includes unlimited-traffic Tunnels, basic WAF, and CDN.
- Zero Trust Security: Tunnels use outbound-only connections, hiding the origin server’s real IP and completely mitigating DDoS attacks.
- Global CDN Acceleration: Via Anycast technology, mobile clients accessing
wwworaisubdomains automatically connect to the nearest edge node.
2. Logical Architecture#
- Endpoint: Mac mini (M-series)
- Stack:
- Port 1313: Hugo (Static Site)
- Port 6180: FastAPI +
uv(AI Agent Backend)
- Tunnel: The
cloudflaredprocess acts as a Connector, mapping local ports to public-facing hostnames.
3. Deployment Steps (Step-by-Step)#
A. Environment Setup#
# 1. Install the driver
brew install cloudflared
cloudflared tunnel login
# 2. Create the tunnel
cloudflared tunnel create mac-vpsB. Ingress Rule Configuration (config.yml)#
Edit the config file under ~/.cloudflared/ to define traffic routing:
tunnel: <TUNNEL_ID>
credentials-file: /Users/<USER>/.cloudflared/<TUNNEL_ID>.json
ingress:
- hostname: www.frank-zhang.com
service: http://localhost:1313
- hostname: ai.frank-zhang.com
service: http://localhost:6180
- service: http_status:404C. Activate DNS Routing#
cloudflared tunnel route dns mac-vps www.frank-zhang.com
cloudflared tunnel route dns mac-vps ai.frank-zhang.com4. Backend Persistence (Production Ready)#
Manually running hugo server or uv run is only suitable for testing. In a production environment, services must restart automatically after a system reboot:
- Tunnel: Run
sudo cloudflared service installto register it as a system daemon. - App Layer: Use PM2 to manage the Python environment and static server:
pm2 start "uv run uvicorn main:app --port 6180" --name "ai-backend"
pm2 start "hugo server --bind 0.0.0.0 --port 1313" --name "hugo-blog"
pm2 save5. Conclusion#
This architecture maintains full data sovereignty (data never leaves your local machine) while leveraging Cloudflare for industrial-grade public connectivity. It provides a robust infrastructure foundation for deploying RAG-based knowledge bases or locally autonomous AI Agents.
Engineer’s Note Before running the
hugobuild command, always verify thatbaseURLinhugo.tomlhas been updated tohttps://www.frank-zhang.com/. If not, some static assets (JS/CSS) may fail to load in the public environment.