A complete walkthrough of turning an idle Mac mini into an always-online server with Cloudflare Tunnel.
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.
Make sure you have a Cloudflare account
Get your Mac mini ready
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
Verify the installation
cloudflared --version
You should see something like cloudflared version 2025.5.0
Log in to your Cloudflare account
cloudflared tunnel login
This opens a browser window asking you to log in to Cloudflare and authorize cloudflared
Create a tunnel
cloudflared tunnel create mac-mini-tunnel
Here mac-mini-tunnel is your tunnel's name—call it whatever you like
Once it's created, you'll see a UUID and a credentials file path. Write down the UUID—you'll need it later
Create the config file
mkdir -p ~/.cloudflared
nano ~/.cloudflared/config.yml
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.
Log in to the Cloudflare dashboard
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
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
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
Now that the tunnel is up, you can install whatever services you want on the Mac mini. Here are a couple of simple examples:
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
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
Visit the domains you set up in a browser, e.g. https://mac-mini.yourdomain.com or https://nextcloud.yourdomain.com
If everything is configured correctly, you should see the corresponding service pages, with all traffic flowing through Cloudflare's secure tunnel
For extra security, you can set up Cloudflare Zero Trust access policies:
I set up automatic backups for my important data:
Install the restic backup tool
brew install restic
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
Schedule it with crontab
crontab -e
Add:
0 2 * * * ~/scripts/backup.sh > ~/backup.log 2>&1
If the tunnel won't connect:
cloudflared tunnel run mac-mini-tunnel --loglevel debugIf a service can't be reached through its domain:
lsof -i :80 or lsof -i :8080This 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.