The OpenClaw gateway is on 127.0.0.1:18789 (github.com/openclaw/openclaw) and you want to reach it from a phone. Three paths cover ninety-five percent of real deployments. The first is Caddy with automatic Let’s Encrypt — classic reverse-proxy, you control the public IP, the certificate lifecycle is invisible. The second is Cloudflare Tunnel, the inbound-less option where the VPS dials out to Cloudflare and there is no public listener on the VPS at all. The third is mTLS in front of one or both of the above, for the slice of users who want a client certificate on the device side too.
Pick one of the first two as your primary path. The third — mTLS — layers on top of either.
What’s happening
The OpenClaw gateway speaks HTTP on 127.0.0.1:18789. It does not do TLS. It does not handle authentication beyond what a channel SDK provides for inbound platform webhooks. Putting it on the public internet means putting something in front of it: a reverse proxy that terminates TLS, optionally an identity layer that authenticates the client, and a firewall posture that limits who can reach the proxy in the first place (Private-network architecture for an OpenClaw deployment).
What the three options give you, ranked by inbound exposure:
- Cloudflare Tunnel + Cloudflare Access — zero inbound exposure, SSO/MFA enforced by Cloudflare, public hostname. Best default for personal and team use. The VPS only needs outbound :443.
- Caddy + Let’s Encrypt + mTLS or a magic-link service — the VPS exposes :443 to the public internet, Caddy auto-manages certs, your auth layer is a magic-link service or a client certificate. Best when you want a single, simple, self-contained edge.
- Caddy + Let’s Encrypt + a basic-auth bouncer — the VPS exposes :443 to the public internet, the auth is basic-auth or a forward-auth subrequest, fast to set up. The lightest reasonable edge for a single user.
Tailscale belongs in the same family but is covered as the primary overlay in Private-network architecture for an OpenClaw deployment — when Tailscale is enough on its own, you do not need a public-internet edge at all. This article is the place to look when you do.
Prerequisites
- A running OpenClaw on an IaaS VPS — see Deploying OpenClaw on a small IaaS VPS for 24/7 access or use the manifest from A cloud-init template for OpenClaw on a fresh VPS.
- A domain you control, with DNS managed via Cloudflare (for path 2) or any provider that supports A/AAAA records (for path 1).
- An email address for the Let’s Encrypt ACME account.
- For mTLS: openssl, a place to keep a small private CA, and the willingness to provision a device cert per phone/laptop.
How to verify
When the edge is in place, the public hostname must resolve and serve TLS:
# DNS
dig +short claw.example.com
# 203.0.113.10 (Path 1, public IP)
# 172.66.x.y (Path 2, Cloudflare edge)
# TLS handshake from any internet host
curl -fsS -o /dev/null -w '%{http_code}\n' https://claw.example.com/health
# 200 — or 401 if auth is in front; not a TCP error and not a TLS error
The certificate must be from Let’s Encrypt (Caddy default) or Cloudflare (Tunnel default), valid, with at least a week before expiry:
echo | openssl s_client -servername claw.example.com -connect claw.example.com:443 2>/dev/null \
| openssl x509 -noout -issuer -subject -dates
A request that should not authenticate must not pass:
curl -sk https://claw.example.com/
# 401, 403, or the SSO login page — never a 200 with the dashboard HTML.
Path 1 — Caddy with automatic Let’s Encrypt
Caddy is a single Go binary that does ACME automatically, serves modern TLS by default, and ships a Caddyfile syntax that is short enough to fit on a screen (caddyserver.com). The right install on Ubuntu is the official APT repo.
Install Caddy
sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
| sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
| sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt-get update
sudo apt-get install -y caddy
caddy version
Point DNS at the VPS
Create an A record (and AAAA if you have IPv6) for claw.example.com pointing at the VPS public IP. Wait for propagation:
dig +short A claw.example.com
Open :443 (and :80 briefly)
ACME HTTP-01 needs :80 reachable for the initial cert. Then you can close it again, since Caddy renews on TLS-ALPN-01 by default after the first issue:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
Write the Caddyfile
/etc/caddy/Caddyfile:
{
email you@example.com
}
claw.example.com {
encode zstd gzip
# Reverse-proxy to the local gateway
reverse_proxy 127.0.0.1:18789 {
header_up X-Real-IP {remote_host}
header_up X-Forwarded-Proto {scheme}
}
# Optional: basic-auth bouncer
# basicauth /* {
# yourname JDJhJDEwJEM4ekw5... # caddy hash-password
# }
log {
output file /var/log/caddy/claw.access.log {
roll_size 10MiB
roll_keep 5
}
format json
}
}
Reload Caddy:
sudo systemctl reload caddy
sudo systemctl status caddy
On the first hit to https://claw.example.com/, Caddy:
- Solves the ACME HTTP-01 challenge on
:80. - Issues a Let’s Encrypt certificate.
- Renews automatically before expiry.
The certificate lives at /var/lib/caddy/.local/share/caddy/certificates/ (caddyserver.com — automatic HTTPS) and you should not touch it.
Adding basic-auth
If you uncommented the basicauth block, generate the hash:
caddy hash-password
# Enter password: (your choice)
# JDJhJDEwJEM4ekw5...
Paste the output into the Caddyfile. Reload. The browser will prompt before any request reaches the gateway.
Basic-auth is the rough cut — fine for a single user with a strong password manager, not appropriate for a team. For team use, layer in forward_auth against an Authelia / authentik instance (caddyserver.com — forward_auth). Or skip path 1 entirely and go to path 2.
Closing :80 after the first issue
After the first successful TLS request, Caddy will use TLS-ALPN-01 for renewals as long as :443 is reachable. You can then close :80:
sudo ufw delete allow 80/tcp
If you want to keep HTTP-01 (some networks have weird TLS-ALPN-01 middleboxes), leave :80 open and accept the small public listener — Caddy serves redirects on :80, nothing else.
Path 2 — Cloudflare Tunnel + Cloudflare Access
This is the right default for most personal and team OpenClaw deployments. The VPS makes one outbound HTTPS connection to Cloudflare and never opens an inbound port. Cloudflare Access sits in front of the hostname and enforces SSO before the request even reaches the tunnel (developers.cloudflare.com — Cloudflare Tunnel).
Install cloudflared
curl -fsSL https://pkg.cloudflare.com/cloudflared-keyring.gpg \
| sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" \
| sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt-get update
sudo apt-get install -y cloudflared
Authenticate and create the tunnel
cloudflared tunnel login # opens a browser, picks the Cloudflare zone
cloudflared tunnel create openclaw
# Bind the hostname to the tunnel — Cloudflare adds the CNAME automatically
cloudflared tunnel route dns openclaw claw.example.com
Write the tunnel config
/etc/cloudflared/config.yml:
tunnel: openclaw
credentials-file: /etc/cloudflared/openclaw.json
ingress:
- hostname: claw.example.com
service: http://127.0.0.1:18789
originRequest:
noTLSVerify: true
connectTimeout: 30s
tcpKeepAlive: 30s
# Catch-all — anything else gets a 404
- service: http_status:404
Move the credentials JSON into /etc/cloudflared/ and tighten perms:
sudo mv ~/.cloudflared/<tunnel-uuid>.json /etc/cloudflared/openclaw.json
sudo chown root:root /etc/cloudflared/openclaw.json
sudo chmod 0600 /etc/cloudflared/openclaw.json
Run as a service:
sudo cloudflared service install
sudo systemctl enable --now cloudflared
sudo systemctl status cloudflared
journalctl -u cloudflared -f
Configure Cloudflare Access
In the Cloudflare dashboard, go to Zero Trust > Access > Applications and add a self-hosted application for claw.example.com:
- Policy: require SSO email match against your address, or your team’s Google/Microsoft tenant.
- Session duration: 24 hours is reasonable; tighter if you want.
- Identity providers: at least one — Google, Microsoft, GitHub, or a SAML IdP.
The policy editor is at developers.cloudflare.com — Self-hosted apps.
Without an Access policy in front of the hostname, the tunnel is a public, unauthenticated path to the gateway — equivalent to running Caddy on :443 with no auth at all. Always pair the tunnel with Access.
Verify
# From any internet host — should redirect to the Cloudflare Access login page
curl -fsSL -o /dev/null -w '%{url_effective}\n%{http_code}\n' https://claw.example.com/
# https://<your-team>.cloudflareaccess.com/cdn-cgi/access/login/claw.example.com
# 200
# On the VPS, the tunnel daemon should be active
systemctl is-active cloudflared # active
Optional layer — mTLS for sensitive endpoints
Mutual TLS adds a client-certificate check on top of either path. The use case is narrow but real: when you have a small set of trusted devices (your phone, your laptop, a colleague’s laptop) and you want a second factor that does not depend on the SSO chain at all.
The model is: a tiny private CA that you control, a client certificate provisioned per device, and the proxy refuses any connection that does not present a valid client cert. Lost device, revoke the cert.
Generate a CA
On a secure host (not the OpenClaw VPS — keep the CA key off the box):
mkdir -p ~/openclaw-ca && cd ~/openclaw-ca
# Root key (4096 RSA — or use ed25519 for smaller certs)
openssl genrsa -out openclaw-ca.key 4096
# Root cert, 10-year validity
openssl req -x509 -new -nodes -key openclaw-ca.key -sha256 -days 3650 \
-subj "/CN=OpenClaw mTLS CA" \
-out openclaw-ca.crt
# Copy the cert (NOT the key) to the VPS
scp openclaw-ca.crt openclaw-vps:/etc/openclaw/openclaw-ca.crt
The OpenSSL docs are at openssl.org/docs.
Issue a client cert per device
# Per device — replace "horia-iphone" with the device name
DEVICE=horia-iphone
openssl genrsa -out $DEVICE.key 2048
openssl req -new -key $DEVICE.key -subj "/CN=$DEVICE" -out $DEVICE.csr
openssl x509 -req -in $DEVICE.csr \
-CA openclaw-ca.crt -CAkey openclaw-ca.key -CAcreateserial \
-out $DEVICE.crt -days 365 -sha256
# Bundle into a .p12 for installing on iOS/Android/macOS
openssl pkcs12 -export -out $DEVICE.p12 \
-inkey $DEVICE.key -in $DEVICE.crt -certfile openclaw-ca.crt \
-name "OpenClaw - $DEVICE"
AirDrop / email the .p12 to the device. iOS installs client certs via Settings > Profile Downloaded; Android via Settings > Security > Encryption & credentials.
Configure Caddy (Path 1) to require mTLS
Add to the Caddyfile site block:
claw.example.com {
tls {
client_auth {
mode require_and_verify
trusted_ca_cert_file /etc/openclaw/openclaw-ca.crt
}
}
reverse_proxy 127.0.0.1:18789
}
Reload Caddy. Any request that does not present a client cert signed by your CA now fails the TLS handshake before the gateway sees a single byte (caddyserver.com — TLS directive).
Configure Cloudflare Tunnel (Path 2) for mTLS
Cloudflare supports mTLS at the Access layer, not the Tunnel layer. In Zero Trust > Access > Service Auth > Mutual TLS, upload your CA’s certificate. In the Access policy for claw.example.com, add a “client certificate from <your CA>” requirement (developers.cloudflare.com — Mutual TLS).
Revoking a device
Remove the device’s .crt from your CA workspace and rebuild the CRL. Caddy supports CRL OCSP stapling via the tls.crl config — or, more pragmatically for a small CA, just shorten the per-device cert validity to 90 days and let expiry handle the lifecycle.
When to pick which
| Situation | Pick | Why |
|---|---|---|
| Personal, single user, you trust Cloudflare | Cloudflare Tunnel + Access | Zero inbound, SSO done for you |
| Personal, single user, prefer to avoid Cloudflare | Caddy + basic-auth | Simple, self-contained |
| Small team, want SSO without buying anything | Cloudflare Tunnel + Access | The free tier covers up to 50 users |
| Sensitive workload (banking integrations, etc.) | Either + mTLS | Device-level auth in addition to SSO |
| Tightest possible posture, willing to live on a tailnet | Tailscale only (Private-network architecture) | No public hostname at all |
You can run more than one in parallel. A common setup is Tailscale for daily access from your own devices and a Cloudflare Tunnel for a friend or family member who is not on your tailnet.
Common mistakes
Pointing the public hostname at the VPS and not putting auth in front. If claw.example.com reaches the gateway with no Caddy auth or no Cloudflare Access policy, it is just a public, unauthenticated agent that runs shell commands. Always have an auth layer.
Forgetting the noTLSVerify: true in the Cloudflare Tunnel config. The gateway speaks plain HTTP on 127.0.0.1:18789. The tunnel daemon needs noTLSVerify: true (because there is no TLS to verify) — otherwise the tunnel refuses the upstream connection.
Using a wildcard cert from a manual issuer when Let’s Encrypt would have done it. Caddy’s automatic flow handles the cert lifecycle. Manual wildcard certs are a maintenance burden you do not need for a single hostname.
Storing the Cloudflare Tunnel credentials file in /home/<user>/. Move it to /etc/cloudflared/ and chmod 0600. A user-readable tunnel credentials file is enough for a hostile process to redirect the tunnel.
mTLS without a documented revocation path. A client cert is only as strong as the way you remove a lost device’s cert. Document the revoke procedure when you set up mTLS, not when a device goes missing.
Related
- Private-network architecture for an OpenClaw deployment
- Firewall rules for an OpenClaw IaaS deployment
- Deploying OpenClaw on a small IaaS VPS for 24/7 access
Sources
- openclaw.ai
- github.com/openclaw/openclaw
- caddyserver.com — docs
- caddyserver.com — automatic HTTPS
- caddyserver.com — TLS directive
- developers.cloudflare.com — Cloudflare Tunnel
- developers.cloudflare.com — Self-hosted apps
- developers.cloudflare.com — Mutual TLS
- letsencrypt.org
- openssl.org/docs
Last verified on OpenClaw current.