Setting up wildcard SSL with Cloudflare DDNS and NPM
Sync a dynamic home IP with Cloudflare DDNS and issue auto-renewing wildcard SSL certificates using Nginx Proxy Manager and DNS-01 challenges.
Exposing a homelab on a residential internet line requires two things: automatic IP tracking and a reverse proxy that terminates TLS cleanly. This guide walks through syncing a dynamic public IP with Cloudflare DDNS and issuing an auto-renewing wildcard certificate (
*.namju.kim) in Nginx Proxy Manager using DNS-01 validation.
Three hurdles when exposing a homelab
Running a personal server on a Mac mini or a small x86 box starts out simple on a local 192.168.x.x subnet. Once you want to reach your dev APIs, Portainer, or self-hosted wiki from outside your home network, residential ISPs introduce three friction points you don’t deal with on AWS or GCP:
- Dynamic public IPs: Residential ISPs reassign public IPv4 addresses on router reboots or DHCP lease expiry. Any static DNS
Arecord eventually points to a stale address and cuts off external access. - Port-forwarding sprawl: Opening a separate router port for every service (
8080,9000,3000, and so on) turns your firewall rules into a mess and widens your attack surface. - Blocked port 80 and Let’s Encrypt rate limits: Some ISPs block inbound port 80, which breaks standard HTTP-01 certificate validation. Even when port 80 is open, issuing separate certificates for every subdomain (
portainer.namju.kim,git.namju.kim,api.namju.kim) increases renewal failure points and risks hitting Let’s Encrypt’s weekly rate limits.
Pairing Cloudflare DDNS with Nginx Proxy Manager (NPM) and a DNS-01 wildcard certificate solves all three problems with a single gateway stack.
Architecture and traffic flow
When a browser requests https://subdomain.namju.kim, traffic moves through Cloudflare DNS, your home router, and NPM before reaching the target container on an isolated Docker bridge network:
flowchart TD
Client["External Browser<br/>(https://*.namju.kim)"]
subgraph Cloudflare["Cloudflare DNS & API"]
CF_DNS["Authoritative DNS<br/>(namju.kim / *.namju.kim)"]
CF_API["Cloudflare API<br/>(Zone:DNS:Edit)"]
end
subgraph HomeRouter["Home Router"]
PF["Port Forwarding<br/>(80/443 -> Homelab 80/443)"]
end
subgraph Gateway["Gateway Stack (Docker)"]
DDNS["Cloudflare DDNS<br/>(Updates A record every 5m)"]
NPM["Nginx Proxy Manager<br/>(TLS Termination *.namju.kim)"]
Certbot["Certbot DNS-01<br/>(TXT Record Validation)"]
end
subgraph Services["Internal Containers (npm-network)"]
SVC1["Portainer (:9000)"]
SVC2["Vaultwarden (:80)"]
SVC3["Dev API (:8080)"]
end
Client -->|"1. DNS lookup"| CF_DNS
CF_DNS -.->|"2. Current public IP"| Client
Client -->|"3. HTTPS :443"| PF
PF -->|"4. Forward"| NPM
DDNS -->|"Sync public IP"| CF_API
Certbot -->|"Create/remove TXT record"| CF_API
NPM -->|"5. Proxy pass"| SVC1
NPM -->|"5. Proxy pass"| SVC2
NPM -->|"5. Proxy pass"| SVC3
Here’s what each component owns:
- Cloudflare DDNS: Checks your current public IPv4 address every 5 minutes and calls the Cloudflare API only when the address changes.
- DNS-01 challenge: Instead of proving ownership over HTTP port 80, Certbot temporarily creates a
_acme-challenge.namju.kimTXTrecord via the Cloudflare API. This works even if your ISP blocks port 80, and it’s required for wildcard certificates (*.namju.kim). - Nginx Proxy Manager (NPM): Terminates HTTPS on port 443 using the wildcard certificate and forwards decrypted traffic by hostname to backend containers attached to
npm-network.
Step 1: Create a scoped Cloudflare API token
Both DDNS updates and DNS-01 challenges talk to the Cloudflare API. Follow least privilege and create a zone-scoped API token instead of reusing your Global API Key.
Never put your Cloudflare Global API Key in a homelab
.envfile or NPM credentials box. If that host is compromised, an attacker gets full control over every domain and setting in your Cloudflare account.
- Sign in to the Cloudflare Dashboard and open My Profile -> API Tokens.
- Click Create Token, then scroll to Create Custom Token and click Get started.
- Configure the token with the minimum required permissions:
- Token name:
homelab-dns-controller - Permissions:
Zone->DNS->EditZone->Zone->Read
- Zone Resources:
Include->Specific zone->namju.kim(select your own domain)
- TTL / Client IP Filtering: Optional; restrict if you want extra guardrails.
- Token name:
- Create the token and save the 40-character secret in a password manager. Cloudflare displays it only once.
Step 2: Deploy Cloudflare DDNS and NPM with Docker Compose
Keeping Cloudflare DDNS and NPM in one compose.yaml file lets you manage the entire ingress layer together and pre-create the shared npm-network bridge for downstream services.
Separate secrets in .env
Keep tokens and host-specific ports out of compose.yaml:
1
2
3
4
5
6
7
8
9
# .env (homelab gateway stack directory)
TZ=Asia/Seoul
# Cloudflare DDNS settings
CF_API_TOKEN=v1.0-masked-token-xxxx-your-real-token
CF_DOMAINS=namju.kim,*.namju.kim
# NPM admin web UI port (keep internal to LAN/VPN)
NPM_ADMIN_PORT=81
Never forward port 81 on your router to the public internet. Access the NPM admin console only from your local LAN (
192.168.x.x:81) or over a private VPN such as Tailscale or WireGuard.
Define compose.yaml
I use favonia/cloudflare-ddns (a tiny, reliable Go binary) for IP synchronization and jc21/nginx-proxy-manager for reverse proxying and certificate renewal:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# compose.yaml (homelab gateway stack)
name: homelab-gateway
services:
# 1. Cloudflare Dynamic DNS updater
cloudflare-ddns:
image: favonia/cloudflare-ddns:latest
container_name: cloudflare-ddns
restart: unless-stopped
environment:
- CLOUDFLARE_API_TOKEN=${CF_API_TOKEN}
- DOMAINS=${CF_DOMAINS}
- PROXIED=false # DNS Only (grey cloud) for direct homelab connections
- UPDATE_CRON=@every 5m # Poll public IP every 5 minutes
- IP6_PROVIDER=none # Disable IPv6 on IPv4-only residential lines
- TZ=${TZ}
network_mode: host # Use host networking for accurate public IP detection
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# 2. Nginx Proxy Manager core
nginx-proxy-manager:
image: jc21/nginx-proxy-manager:latest
container_name: nginx-proxy-manager
restart: unless-stopped
ports:
- "80:80" # Standard HTTP inbound
- "443:443" # Standard HTTPS inbound
- "${NPM_ADMIN_PORT}:81" # Admin web console
environment:
- DISABLE_IPV6=true
- TZ=${TZ}
volumes:
- ./data:/data # NPM config, proxy hosts, and SQLite DB
- ./letsencrypt:/etc/letsencrypt # Persisted Let's Encrypt certificates
networks:
- npm-network
depends_on:
- cloudflare-ddns
networks:
npm-network:
name: npm-network
driver: bridge
Start the stack and verify that DDNS resolves and updates your A records:
1
2
docker compose up -d
docker logs -f cloudflare-ddns
1
2
3
4
5
6
# Expected startup log
INFO: favonia/cloudflare-ddns ...
INFO: Checking public IP addresses...
INFO: Detected IPv4 address: 121.135.xxx.xxx
INFO: Updating DNS records for namju.kim and *.namju.kim...
INFO: Successfully updated DNS records.
Step 3: Issue a wildcard SSL certificate via DNS-01
Before issuing the certificate, configure your home router to forward external TCP ports 80 and 443 to your homelab’s static LAN IP (for example, 192.168.0.50:80 and 192.168.0.50:443).
- Open
http://192.168.0.50:81in your browser.- Default credentials:
admin@example.com/changeme. - Change both the email and password immediately on first login.
- Default credentials:
- Go to SSL Certificates -> Add SSL Certificate -> Let’s Encrypt.
- Fill out the form:
- Domain Names:
*.namju.kim,namju.kim(press Enter after each) - Email Address for Let’s Encrypt: Your real email for expiration notices
- Use a DNS Challenge: ON
- DNS Provider:
Cloudflare - Credentials File Content:
1 2
# Replace the placeholder with your scoped API token dns_cloudflare_api_token = v1.0-masked-token-xxxx-your-real-token
- Propagation Seconds:
120(more reliable than the 30-second default) - I Agree to the Let’s Encrypt Subscriber Agreement: ON
- Domain Names:
- Click Save. Certbot creates the temporary
_acme-challengeTXT record through Cloudflare, completes validation with Let’s Encrypt, and stores the wildcard certificate under./letsencrypt.
Once issued, *.namju.kim, namju.kim appears in the SSL list with a 90-day validity period and automatic background renewal enabled.
Step 4: Route subdomains with proxy hosts
With the wildcard certificate ready, adding a new service takes two small steps: attach the service container to npm-network and map a subdomain in NPM. Here’s an example routing Portainer (portainer:9000) to portainer.namju.kim.
Attach the backend service to npm-network
Reference npm-network as an external network in the target service’s compose.yaml. Notice that you don’t need to publish port 9000 to the host at all—NPM talks to portainer:9000 directly over Docker’s internal bridge DNS.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# portainer/compose.yaml
services:
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
networks:
- npm-network # Shared bridge network with NPM
volumes:
portainer_data:
networks:
npm-network:
external: true
Add the proxy host in NPM
- In NPM, open Hosts -> Proxy Hosts -> Add Proxy Host.
- On the Details tab:
- Domain Names:
portainer.namju.kim - Scheme:
http - Forward Hostname / IP:
portainer(resolved via Docker’s embedded DNS onnpm-network) - Forward Port:
9000 - Cache Assets: OFF
- Block Common Exploits: ON
- Websockets Support: ON
- Domain Names:
- On the SSL tab:
- SSL Certificate: Select
*.namju.kim, namju.kim - Force SSL: ON (301 redirects HTTP to HTTPS)
- HTTP/2 Support: ON
- HSTS Enabled: ON
- SSL Certificate: Select
- Click Save to compile and reload the Nginx config immediately.
Always turn on Websockets Support for apps that rely on live bidirectional streams—such as Portainer’s container exec console, live log viewers, or Nextcloud file sync. Without it, interactive terminals disconnect immediately.
Opening https://portainer.namju.kim from outside your network now serves the dashboard over valid HTTPS backed by your wildcard certificate.
Operational trade-offs and checklist
Cloudflare Proxy (orange cloud) vs. DNS Only (grey cloud)
In the compose.yaml above, I intentionally set PROXIED=false (DNS Only). Choose based on your workload:
| Criteria | DNS Only (Grey cloud, default here) | Cloudflare Proxied (Orange cloud) |
|---|---|---|
| Home IP visibility | Exposed in DNS A record | Hidden behind Cloudflare edge IPs |
| TLS termination | Handled directly by NPM wildcard cert | Edge cert + origin cert (Full (Strict)) |
| Upload size limit | Controlled by Nginx client_max_body_size | Hard 100 MB per-request cap on Free plan |
| Media & non-HTTP traffic | No proxy restrictions | Large video streaming can violate ToS or throttle |
If you host Nextcloud file uploads or Jellyfin/Plex streaming, keep PROXIED=false—or split heavy-transfer subdomains onto DNS Only while proxying lightweight web apps. When you don’t want to expose your home IP or open router ports at all (for example, behind CGNAT), skip port forwarding and use Cloudflare Tunnel or Tailscale instead.
Verify automatic certificate renewal
NPM runs a background Certbot cron job that attempts renewal once a certificate is within 30 days of expiration. You can verify that your Cloudflare token and DNS-01 hook still work without waiting two months:
1
docker exec -it nginx-proxy-manager certbot renew --dry-run
If the dry run succeeds with zero errors, renewals will run unattended every 60–90 days.
Pre-flight checklist
- Cloudflare API token is scoped strictly to
Zone:DNS:EditandZone:Zone:Readon a single zone. - Router forwards only TCP
80and443to the homelab; NPM admin port81stays internal. docker logs cloudflare-ddnsconfirmsnamju.kimand*.namju.kimmatch your current public IP.certbot renew --dry-runpasses inside thenginx-proxy-managercontainer.- Websockets Support, Force SSL, and HTTP/2 Support are enabled on interactive proxy hosts.