← Back to all posts

Self-host your-site.com with Cloudflare Tunnel on Ubuntu

Self-host your-site.com with Cloudflare Tunnel on Ubuntu

Introduction

In this article, we’ll turn a PC running Ubuntu 24.04 into a self-hosted web server using the domain your-site.com, exposed to the internet with Cloudflare Tunnel. No need to open ports on your router.

Prerequisites

  • A PC running Ubuntu 24.04
  • A domain name (e.g., your-site.com) managed by Cloudflare
  • A free Cloudflare account
  • Your HTML site saved in /var/www/your-site/index.html

Step 1 – Install Cloudflared

wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb

Step 2 – Connect to your Cloudflare account

cloudflared tunnel login

A browser tab will open where you can log in and authorize your Ubuntu machine with your Cloudflare account.

Step 3 – Create a Cloudflare Tunnel

cloudflared tunnel create your-site-tunnel

This creates a your-site-tunnel.json file in ~/.cloudflared/ containing your tunnel credentials.

Step 4 – Launch a temporary local web server

cd /var/www/your-site
python3 -m http.server 3000

Your HTML site is now available at http://localhost:3000.

Step 5 – Create the tunnel config file

sudo nano /etc/cloudflared/config.yml

File content:

tunnel: your-site-tunnel
credentials-file: /home/<your_user>/.cloudflared/<UUID>.json

ingress:
  - hostname: your-site.com
    service: http://localhost:3000
  - service: http_status://404

Step 6 – Add DNS record automatically

cloudflared tunnel route dns your-site-tunnel your-site.com

This command creates a CNAME record from your-site.com to your Cloudflare Tunnel.

Step 7 – Run the tunnel

cloudflared tunnel run your-site-tunnel

Cloudflare will now forward traffic from https://your-site.com to your local server.

Step 8 – Test it live

Open your browser and go to:

https://your-site.com

🎉 You should now see your HTML file load without any router configuration or port forwarding.

Conclusion

Cloudflare Tunnel is a powerful solution to expose local websites, APIs, or dashboards to the internet securely and easily. Once your static site is live, you can later switch to Next.js, Node.js or Docker apps on port 3000 using the same tunnel.

Publish on:2025-07-26
Self-host your-site.com with Cloudflare Tunnel on Ubuntu | James Dev Blog