Host a Website on a Google Cloud VM with Cloudflare Tunnel

Host a Website on a Google Cloud VM with Cloudflare Tunnel

November 15, 2026 |

You can run a small web server on a Google Cloud Compute Engine VM and make it available at your own domain with Cloudflare Tunnel. The tunnel connects outbound from the VM to Cloudflare, so you don’t need to open an inbound web port or point your domain at a changing VM address.

This is a good way to learn the basics of virtual machines, SSH, web servers, DNS, and tunnels. It is not necessarily a $0 setup, though: read the cost notes before creating resources.

What you’ll need

  • A Google Cloud project with billing enabled and the Compute Engine API available.
  • A Cloudflare account and a domain active on Cloudflare. You can buy a domain through a registrar and use Cloudflare’s nameservers.
  • Install the Google Cloud CLI (gcloud) using Google’s OS-specific installation instructions, then run gcloud init to sign in. The steps below set the project and zone for this tutorial.

Check the costs first

Google Cloud’s Always Free usage limits include one non-preemptible e2-micro VM for eligible usage in specific US regions, up to 30 GB of Standard Persistent Disk, and a limited amount of internet egress. The free allowance is subject to Google’s terms and monthly limits; it does not cover every resource associated with a VM.

In particular, an external IPv4 address attached to a running VM is billed separately. Google’s VPC pricing currently lists a charge of $0.005 per hour for an in-use external IPv4 address—about $3.65 for a 730-hour month. Internet egress beyond the applicable free allowance and your domain registration are additional possible costs. Check the current prices and your billing account before proceeding.

For the example below, we’ll use an external IPv4 address so gcloud compute ssh can connect in the usual way and the VM can reach the internet. Cloudflare Tunnel means you do not need to add an inbound firewall rule for HTTP or HTTPS. If you want to avoid the public-IP charge, plan a different SSH and outbound-network setup (for example, IAP and Cloud NAT) and check their costs as well.

Create the VM

  1. In the Google Cloud console, create or select a project, link a billing account, and enable the Compute Engine API.
  2. Create a VM instance. For this example, use:
    • Name: always-free-vm
    • Region and zone: us-central1 and us-central1-a
    • Machine type: e2-micro
    • Boot disk: an Ubuntu image with a 30 GB Standard Persistent Disk
    • External IPv4: enabled
  3. Keep the default network settings for the tutorial. Do not add an ingress firewall rule for ports 80 or 8000; the tunnel will carry public web requests to the VM.

An e2-micro is a shared-core machine with 1 GB of memory. The selected region, machine, disk type and size must match the current Free Tier requirements for the compute and disk usage to qualify.

Connect to the VM

Set the project and default zone in your local terminal. Replace learning-devops if your project has a different ID:

gcloud config set project learning-devops
gcloud config set compute/zone us-central1-a

Connect to the instance:

gcloud compute ssh always-free-vm

The first connection may prompt gcloud to create an SSH key and add its public key to the project. You can also use gcloud compute config-ssh to add SSH aliases for your instances to ~/.ssh/config; Google documents that command here.

Run a small web server

For a quick test, create a page and serve it on the VM’s loopback interface:

mkdir -p ~/site
printf '<h1>It works!</h1>\n' > ~/site/index.html
cd ~/site
python3 -m http.server 8000 --bind 127.0.0.1

Leave that command running while you test the site. In another SSH session, check that the server responds locally:

curl http://127.0.0.1:8000

This built-in Python server is for a simple demonstration, not production hosting. Because it runs in the foreground, it will stop when you end that session or restart the VM; use a service manager to keep a real application running persistently.

Create a Cloudflare Tunnel

First, make sure your domain is using Cloudflare DNS. If you register a domain elsewhere, follow Cloudflare’s instructions to add the domain and update its nameservers at your registrar. If you’re shopping for a low-cost name, try searching for a short numeric .xyz domain (for example, six to ten digits), but compare the renewal price as well: domain prices vary, and promotional first-year prices can renew for more. 2000026.xyz is the domain used in this walkthrough.

Then create the tunnel:

  1. In the Cloudflare dashboard, go to Networking > Tunnels and select Create Tunnel.
  2. Name it (for example, free-vm-tunnel) and select the VM’s operating system and architecture.
  3. Copy the install-and-run command Cloudflare provides.
  4. In your VM’s SSH session, paste and run that command. The command includes a tunnel token, so treat it like a password and don’t publish it.
  5. Wait for the tunnel to appear as Healthy in the dashboard.

Cloudflare’s current setup guide provides the up-to-date dashboard labels and install commands. A tunnel connector needs outbound network access to Cloudflare (including port 7844); it does not require an inbound web port to be open on the VM.

Publish the website

In the Cloudflare dashboard, open your tunnel and add a route:

  1. Under Routes, select Add route > Published application.
  2. Enter a hostname, such as free.2000026.xyz, and choose your domain.
  3. Set the Service URL to http://localhost:8000.
  4. Add the route.

Cloudflare creates the DNS record for the hostname and proxies visitor HTTPS traffic to the local HTTP service through the tunnel. Open https://free.2000026.xyz in a browser to see the page. Replace that example hostname with one under your own domain.

If the page doesn’t load, check that the Python server is still running, the service URL uses the correct port, and the tunnel is Healthy. Also check that outbound traffic to Cloudflare is not blocked by a firewall.

Start and stop the VM

You can list instances and their state with:

gcloud compute instances list

Stop the VM when you don’t need it:

gcloud compute instances stop always-free-vm

Start it again with:

gcloud compute instances start always-free-vm

Stopping the VM makes the website unavailable until it starts again. The tunnel service can reconnect when the VM is running, but the Python test server must be started again. Stopping a VM also does not necessarily stop all charges—for example, persistent disks remain allocated—so review your billing report and clean up resources you no longer need.

Billing

Use Cloud Billing to check what the project is actually costing:

  1. In the Google Cloud console, open Billing > Reports. You can also go directly to the Billing Reports page.
  2. Select Current month for the time range and filter by the project you created for this tutorial. If the report includes other projects, make sure the project filter is set before reviewing the totals.
  3. Review the report’s cost and savings information, and group by service or SKU to see what is contributing to the total. The Reports guide explains the available filters and how to read the report.

For an itemized view of a completed billing month, open Billing > Cost table. Select the invoice month you want to inspect; the table lists costs and any applicable credits. See Google’s Cost table guide for details.

The Reports page is useful for tracking current-month usage, while the Cost table is organized around invoice months. Your access to billing data depends on your project and billing-account permissions.

Further reading