All Posts

Turning an Idle Mac mini into an Online Server with Cloudflare Tunnel

A complete walkthrough of turning an idle Mac mini into an always-online server with Cloudflare Tunnel.

Published Dec 12, 2024·5 min read

The Setup

  • Mac mini (2018)
    • macOS Sonoma 14.5
    • 3.6 GHz quad-core Intel Core i3
    • 8GB RAM
    • 256GB SSD
  • Cloudflare
    • Free account
    • A domain I own

References

Background

When I moved last year, I rediscovered a Mac mini I'd bought a few years back, forgotten in a corner and collecting dust. It's actually a pretty capable little machine—too good to throw away—and I'd been wanting a home server to host some personal projects anyway. The catch: my apartment's network doesn't allow direct access to devices on the LAN from outside, and I didn't want to expose my home network's IP address either.

After some digging, I found that Cloudflare Tunnel was the perfect solution—it lets my Mac mini publish services to the internet securely, with no public IP and no open ports required. Here's the complete walkthrough of how I set it up.

Steps

Prep Work

  1. Make sure you have a Cloudflare account

    • Sign up for a free Cloudflare account
    • Add your domain to Cloudflare for management (if you haven't done this already)
  2. Get your Mac mini ready

    • Make sure the Mac mini is updated to the latest OS version
    • Keep the machine powered on and connected to the network

Installing Cloudflared

  1. Install cloudflared with Homebrew

    • If you don't have Homebrew yet, install it first:

      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
    • Install cloudflared:

      brew install cloudflare/cloudflare/cloudflared
      
  2. Verify the installation

    cloudflared --version
    

    You should see something like cloudflared version 2025.5.0

Logging In and Creating a Tunnel

  1. Log in to your Cloudflare account

    cloudflared tunnel login
    

    This opens a browser window asking you to log in to Cloudflare and authorize cloudflared

  2. Create a tunnel

    cloudflared tunnel create mac-mini-tunnel
    

    Here mac-mini-tunnel is your tunnel's name—call it whatever you like

  3. Once it's created, you'll see a UUID and a credentials file path. Write down the UUID—you'll need it later

Configuring the Tunnel

  1. Create the config file

    mkdir -p ~/.cloudflared
    nano ~/.cloudflared/config.yml
    
  2. Add the following to the config file, replacing your-tunnel-uuid with the UUID you noted earlier

    tunnel: your-tunnel-uuid
    credentials-file: /Users/你的用户名/.cloudflared/your-tunnel-uuid.json
    
    ingress:
      - hostname: mac-mini.yourdomain.com
        service: http://localhost:80
      - hostname: nextcloud.yourdomain.com
        service: http://localhost:8080
      - service: http_status:404
    

    This config forwards traffic for mac-mini.yourdomain.com to local port 80, and traffic for nextcloud.yourdomain.com to local port 8080. Adjust these to fit your own needs.

Adding DNS Records

  1. Log in to the Cloudflare dashboard

  2. Add CNAME records for your tunnel

    cloudflared tunnel route dns mac-mini-tunnel mac-mini.yourdomain.com
    cloudflared tunnel route dns mac-mini-tunnel nextcloud.yourdomain.com
    

    This automatically adds the necessary CNAME records to Cloudflare DNS

Running the Tunnel

  1. Start the tunnel manually to test it

    cloudflared tunnel run mac-mini-tunnel
    

    If everything's working, you should see output like 2025-05-06T16:30:00Z INF Tunnel mac-mini-tunnel successfully established connections

  2. Install the tunnel as a system service so it starts automatically

    sudo cloudflared service install
    

    This creates a LaunchDaemon so the tunnel runs automatically at system startup

Installing and Configuring Your Services

Now that the tunnel is up, you can install whatever services you want on the Mac mini. Here are a couple of simple examples:

  1. A simple website (using nginx)

    brew install nginx
    sudo nano /usr/local/etc/nginx/nginx.conf
    

    Configure nginx to listen on port 80, then start it:

    brew services start nginx
    
  2. Nextcloud cloud storage

    You can spin it up quickly with Docker:

    brew install docker docker-compose
    mkdir ~/nextcloud
    cd ~/nextcloud
    

    Create a docker-compose.yml file:

    version: '3'
    services:
      nextcloud:
        image: nextcloud
        ports:
          - 8080:80
        volumes:
          - ./data:/var/www/html
        restart: always
    

    Start the service:

    docker-compose up -d
    

Testing Access

  1. Visit the domains you set up in a browser, e.g. https://mac-mini.yourdomain.com or https://nextcloud.yourdomain.com

  2. If everything is configured correctly, you should see the corresponding service pages, with all traffic flowing through Cloudflare's secure tunnel

Advanced Configuration

Enabling Access Control

For extra security, you can set up Cloudflare Zero Trust access policies:

  1. In the Cloudflare dashboard, go to Zero Trust > Access > Applications
  2. Add a new application and select your tunnel and domain
  3. Configure access policies—for example, only allowing specific email addresses

Setting Up Automatic Backups

I set up automatic backups for my important data:

  1. Install the restic backup tool

    brew install restic
    
  2. Set up a simple backup script

    mkdir -p ~/scripts
    nano ~/scripts/backup.sh
    

    Add the following:

    #!/bin/bash
    RESTIC_PASSWORD="your-password" restic -r /Volumes/ExternalDrive/backups backup /path/to/your/data
    
  3. Schedule it with crontab

    crontab -e
    

    Add:

    0 2 * * * ~/scripts/backup.sh > ~/backup.log 2>&1
    

Troubleshooting

Tunnel Connection Issues

If the tunnel won't connect:

  1. Check your network connection
  2. Verify your Cloudflare account status
  3. Check that the config file path is correct
  4. Check the logs: cloudflared tunnel run mac-mini-tunnel --loglevel debug

Service Not Reachable

If a service can't be reached through its domain:

  1. Confirm the local service is actually running: lsof -i :80 or lsof -i :8080
  2. Check that the DNS records are configured correctly
  3. Confirm the ingress rules are configured correctly

Final Thoughts

This setup gave my idle Mac mini a new lease on life as a surprisingly capable home server. I now use it to host my personal website, Nextcloud storage, and a few development projects. The most satisfying part: none of it required a public IP or opening ports on my home network, and all traffic travels encrypted through Cloudflare's secure tunnel.

A Mac mini isn't a server in the traditional sense, but for personal use it's quiet, power-efficient, and plenty fast—a pretty ideal choice. Add the security and convenience of Cloudflare Tunnel, and the combination is just about perfect!

If you've got an idle Mac mini or any other computer lying around, give this a try and put it back to work.