How to Set Up Let’s Encrypt Wildcard Certificates with DNS Validation

How to Set Up Let’s Encrypt Wildcard Certificates with DNS Validation

A Let’s Encrypt wildcard certificate covers a domain and every first-level subdomain under it with one certificate, so app.example.com, api.example.com, and blog.example.com all work without a separate request for each name. Let’s Encrypt only issues wildcard names through DNS validation, which proves control by a TXT record instead of an HTTP file. This guide shows the manual route first, then the plugin route that makes renewal automatic.

Start with a clear picture of what a wildcard covers. A certificate for *.example.com covers one level: shop.example.com yes, eu.shop.example.com no. It also does not cover the bare domain itself unless you request both names, so a normal request lists example.com and *.example.com together. If you only need one or two fixed names, the HTTP route in our guide to installing WordPress on a LEMP stack is simpler, and you should use it instead of adding DNS complexity.

How a Let’s Encrypt Wildcard Certificate Is Validated

DNS validation works like this: Certbot asks Let’s Encrypt for a certificate, Let’s Encrypt replies with a token, Certbot tells you to publish that token as a TXT record at _acme-challenge.example.com, and Let’s Encrypt checks the record through public DNS. When the record matches, the certificate is issued. No web server needs to serve a file, which is why this route works for servers behind a firewall, for services that are not yet live, and for names that point to private addresses.

The catch is timing. DNS records take time to spread, and a check that runs too early fails even though the record is correct. Certbot waits before asking Let’s Encrypt to check, and DNS plugins wait longer, but a slow DNS provider can still break the run. Use a low TTL on the challenge record, wait for the record to show from a public resolver with dig TXT _acme-challenge.example.com, and only then let the check proceed.

Request a Wildcard Certificate by Hand

Install Certbot, then run the manual DNS plugin:

sudo certbot certonly --manual --preferred-challenges=dns -d example.com -d "*.example.com"

Certbot prints a TXT value and waits. Add a TXT record at _acme-challenge.example.com with that exact value, then press enter only after the record is visible in public DNS. Certbot writes the certificate to /etc/letsencrypt/live/example.com/. Point your web server or reverse proxy at fullchain.pem and privkey.pem from that folder, test with sudo nginx -t if you use Nginx, and reload the service.

The manual route has one serious limit: it cannot renew by itself. Certbot cannot add the next TXT record without a human, so a manual wildcard certificate will expire unless someone repeats the process every 90 days. Treat the manual run as a test or a stopgap, and move to a DNS plugin for anything you plan to keep.

Make Renewal Automatic with a DNS Plugin

A DNS plugin talks to your DNS provider API and adds and removes the TXT record for you. The certbot dns plugin for your provider does that work, and a wildcard ssl subdomain setup is the main case where it earns its keep. Certbot ships plugins for many providers, including Cloudflare, Route 53, and DigitalOcean. For Cloudflare, install the plugin and create an API token limited to DNS editing for the zone, then store it in a credentials file with root-only permissions:

sudo apt install -y python3-certbot-dns-cloudflare
sudo chmod 600 /root/.secrets/cloudflare.ini

Then request the certificate with the plugin:

sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /root/.secrets/cloudflare.ini -d example.com -d "*.example.com"

The credentials file must hold the token and nothing else readable by other users. A token with full account access is a needless risk, so scope it to the single zone and to DNS edit only. Test renewal with sudo certbot renew --dry-run. If the dry run passes, the timer will renew the wildcard on its own, and the 90-day expiry stops being a calendar task.

DNS Validation TXT Record Mistakes to Avoid

Three mistakes cause most failures. First, adding the record at the wrong name: the record goes at _acme-challenge.example.com, not at the bare domain and not at the wildcard name. Second, leaving an old challenge value in place next to the new one, which makes the check read the wrong value. Delete the old record before adding the new one. Third, a long TTL on a record you keep reusing, which makes the new value take an hour to spread while the check runs in minutes. Set the TTL to 60 or 120 seconds for challenge records.

Some providers add the zone name to the record name for you, so typing the full name creates a doubled name like _acme-challenge.example.com.example.com. If validation keeps failing with no record found, query the exact name with dig and check what your provider actually published. That one check resolves most cases that look like a Let’s Encrypt problem but are really a provider interface quirk.

Use One Wildcard Across Many Services Safely

A wildcard certificate is convenient, but a single key that serves ten subdomains is also a single key worth stealing. Keep the private key on the server that terminates TLS, and do not copy it to every app server behind it unless those servers need it. Where a reverse proxy fronts your services, terminate TLS at the proxy and keep the key in one place. Our comparison of reverse proxies shows how that front door can work for Docker apps too.

For services that run in containers, the same idea applies: one proxy holds the certificate and routes by subdomain. The guide to free SSL for Docker apps walks through that setup, and the Nginx Proxy Manager guide for multiple sites shows a visual route to the same result. Pick one place to hold the key and one renewal path, and the wildcard stays an asset instead of a sprawl of copies.

Renewal, Expiry, and What to Check Monthly

Wildcard certificates expire after 90 days like any Let’s Encrypt certificate, and the renewal window opens 30 days before expiry. With a DNS plugin, renewal is a background job. Without one, put a reminder at 60 days, not at 89, so a failed manual run still leaves time to fix DNS and retry. A short monthly check covers the rest: run sudo certbot certificates to list expiry dates, confirm the timer is active with systemctl list-timers | grep certbot, and confirm the live site serves the new certificate after a renewal with echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates.

If a renewal fails, read /var/log/letsencrypt/letsencrypt.log before retrying. A revoked or changed API token, a DNS provider outage, and a zone that moved providers all show up there as authentication errors, and retrying without fixing the token only burns rate limit allowance. Fix the credential or the record, run a dry run, and the next real renewal should pass.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.