Connecting Domain to Localhost
-
2. Authenticate with Cloudflare
Now link your server to your Cloudflare account:
cloudflared tunnel login
This command opens a browser window where you can log in and select your domain.
A new certificate file will be stored in~/.cloudflared/cert.pem. -
3. Create the Tunnel
Next, create a new named tunnel:
cloudflared tunnel create mytunnel
This generates a JSON credentials file inside
~/.cloudflared/. -
4. Create the Config File
Now set up the configuration file to expose your local HTTP service:
sudo nano /etc/cloudflared/config.yml
Paste this minimal setup:
tunnel: mytunnel credentials-file: /root/.cloudflared/<TUNNEL_ID>.json ingress: - hostname: example.com service: http://localhost:80 - service: http_status:404 -
5. Run the Tunnel
Finally, start your Cloudflare Tunnel:
cloudflared tunnel run mytunnel
Your HTTP site at
localhost:80is now securely available at https://example.com via Cloudflare. -
6. Optional: Auto-start on Boot
Enable automatic start at boot using systemd:
sudo systemctl enable --now cloudflared
Contents