Custom domain and HTTPS
Learn how to point your own domain name at an Axum app on Fly.io, Render, or Shuttle, how DNS records and platform certificates work, and how HTTPS is enforced
A custom domain is your own address on the internet, such as api.example.com, instead of the address the platform gave you, such as my-axum-app.fly.dev. HTTPS is the encrypted version of HTTP, the padlock in the browser, and it needs a certificate that proves the server really owns that domain. On the three platforms in this chapter, both pieces are the platform's job: you point your domain at the app with DNS records, the platform issues and renews the certificate, and the app itself changes in only one way, by trusting that the platform has already handled the encryption.
Where This Fits
The three platform pages each ended with an app live on a platform address: *.fly.dev, *.onrender.com, and *.shuttle.app. Those addresses work, but they are not yours. A custom domain replaces the platform's name with your own, and HTTPS makes that name safe to use. The app code does not change at all. The work is DNS records, certificate requests, and one redirect setting, and it is the same shape on every platform, with different commands.
Think of a shop that moves from a market stall number to a street address with its own sign. The shop and its food stay the same. The sign tells customers where to find it, and the lock on the door tells them the shop is really the one on the sign. The domain is the sign. The certificate is the lock.
The Smallest Working Version
Every platform follows the same four steps, in this order. The order matters, because the certificate step checks the DNS step, and the redirect step only makes sense once the certificate exists.
Step 1: Buy or choose a domain
Buy the domain from a registrar, such as Namecheap, Cloudflare, or Porkbun, or use one you already own. A domain is a name you rent by the year, and the registrar is the company you rent it from. The registrar also runs the DNS settings where the records from step 2 are added. Pick the name before doing anything else, because every later step names it.
api.example.com
Step 2: Point DNS at the app
Add a DNS record at the registrar that points the domain at the app. A subdomain such as api.example.com uses a CNAME record, which points a name at another name. An apex domain, the bare example.com with nothing in front, uses A and AAAA records, which point a name at IP addresses. The platform tells you the exact values to use, and those values differ per platform, so copy them from the platform, never from memory.
CNAME api.example.com -> my-axum-app.fly.dev
Step 3: Ask the platform for a certificate
Tell the platform to issue a certificate for the domain. The platform proves you own the domain by checking the DNS records, then asks a certificate authority, usually Let's Encrypt, to issue a certificate. The certificate is free on all three platforms, and the platform renews it before it expires, so this is a one-time step.
fly certs add api.example.com
Step 4: Enforce HTTPS
Turn on the redirect that sends plain HTTP requests to HTTPS. Without it, both addresses work, and a visitor who types http:// gets an unencrypted connection. With it, every plain request is redirected to the encrypted address, and the app is always reached securely.
curl -sI http://api.example.com
HTTP/1.1 301 Moved Permanently
Location: https://api.example.com/
No Domain Was Bought or Configured for This Page:
No domain was bought, no DNS records were changed, and no certificate was issued while writing this page. The commands and record shapes below were checked against the Fly.io, Render, and Shuttle documentation, and the Axum behaviour they describe was run live on a local server. Treat the steps as checked against the official docs, not as a domain setup that happened here. DNS changes take time to spread, and certificate checks fail until they have, so expect waiting, not instant results, when you follow them.
DNS Records in Plain Words
DNS is the system that turns names into addresses. When a browser is asked for api.example.com, it asks DNS for the records of that name, follows them to the platform's servers, and then connects. Three record types do almost all the work on this page.
A CNAME record, short for canonical name, points one name at another name. api.example.com as a CNAME to my-axum-app.fly.dev means anyone looking up the first name is sent to the second name, and then to whatever addresses that name resolves to. A CNAME is the right record for a subdomain, because it follows the platform if the platform ever changes its own addresses.
An A record points a name at an IPv4 address, such as 37.16.10.138, and an AAAA record points it at an IPv6 address, such as 2a09:8280:1::1:3e99. These are the records an apex domain needs, because the DNS rules do not allow a CNAME at the apex, the bare domain with nothing in front. The platform shows the exact addresses to use, usually in the certificate or domain settings screen, and they are the platform's anycast addresses, which route each visitor to the nearest region.
A TXT record holds text, and it is used for ownership checks. Some platforms ask for a TXT record to prove the domain is yours before they issue a certificate, and the record's value is a code the platform gives you. The record is only needed for the check, and it can stay in place afterwards without harm.
DNS changes are not instant. Each record has a TTL, a time to live, which says how long other servers may cache the old value, and the change spreads as those caches expire. Waiting an hour after a DNS change before judging whether it worked is normal, and a certificate check that fails ten minutes after a change usually means the change has not spread yet, not that the change is wrong.
Apex and Subdomain Are Different Names:
example.com and www.example.com are two different hostnames, and a certificate for one does not cover the other. Each needs its own DNS records and its own certificate, on every platform. The usual setup is to get certificates for both, and to redirect one to the other, so visitors land on the same place whichever name they type.
HTTPS and Certificates in Plain Words
HTTPS is HTTP with the connection encrypted, and the encryption needs a certificate. A certificate is a small document that ties a domain name to a public key, signed by a certificate authority that browsers trust. When a browser connects, the server shows its certificate, the browser checks the signature and the name, and if both match, the browser encrypts everything it sends.
Let's Encrypt is the certificate authority all three platforms use for free certificates. It issues certificates that last 90 days, and the platforms renew them automatically before they expire, so the short lifetime never becomes a chore. The platform proves ownership to Let's Encrypt with a DNS check or an HTTP check, which is why the DNS step comes first: without the right records, the check fails and no certificate is issued.
The app never sees the certificate. The platform terminates TLS at its edge, which means the platform's servers do the encryption and forward plain HTTP to the app inside. The app binds a plain port, answers plain HTTP, and the certificate lives on the platform. That is why no code change is needed for HTTPS, and why the certificate never appears in the repository.
The Concept Behind a Custom Domain
A domain name is a layer of indirection. The app's real address is a platform name that changes when the platform changes. The domain is a name you own, and it points at whatever the app's current address is. When the app moves to a different platform, the domain's records change, and the app's visitors never notice, because they only ever type the domain.
A beginner can think of it as a phone number that forwards to a mobile. The mobile number changes when the phone changes, but the forwarding number stays the same, and callers never need to know the new number. The domain is the forwarding number. The platform address is the mobile number. DNS is the forwarding service.
Fly.io Custom Domain
On Fly.io, the flow is two commands and the DNS records they report. First, add the certificate:
fly certs add api.example.com
The command prints the DNS records the platform needs, which are A and AAAA records for an apex domain, or a CNAME for a subdomain. Add those records at the registrar, then check the status:
fly certs show api.example.com
fly certs list
The show command reports the certificate state and the DNS records it expects. The state moves to issued once DNS has spread and the platform has validated ownership. If it stalls, the usual cause is a DNS record that has not spread yet, or a conflicting record pointing elsewhere. The check command forces a fresh validation attempt:
fly certs check api.example.com
HTTPS enforcement on Fly.io is the force_https setting in fly.toml, which was already in the Fly.io page:
# fly.toml
[http_service]
internal_port = 3000
force_https = true
With that setting, a plain HTTP request to the custom domain is redirected to HTTPS by the platform, and the app never sees the plain request. The certificate covers the exact hostname it was added for, so add both the apex and the www subdomain when both should work, with a separate fly certs add for each.
Render Custom Domain
On Render, the flow is done in the dashboard. Open the service, go to Settings, then Custom Domains, and add the domain. Render shows the exact DNS record to add, which is a CNAME pointing at the service's onrender.com address for a subdomain, or the addresses Render gives for an apex domain. Add that record at the registrar, and Render provisions a Let's Encrypt certificate automatically, usually within a minute of the DNS change spreading.
Check the result from the terminal:
curl -sI https://api.example.com
HTTP/2 200
A 200 answer over HTTPS, with the app's real response, means the domain, the certificate, and the routing all work. Render enforces HTTPS for custom domains automatically, so there is no redirect setting to turn on. A plain HTTP request to the domain is redirected to HTTPS by the platform.
The free tier includes custom domains, and the included count depends on the workspace plan. The Hobby plan includes 2 custom domains, and extra domains beyond the plan cost a small monthly amount. That limit is per workspace, not per service, so it is worth checking before adding domains to several services.
Shuttle Custom Domain
On Shuttle, the flow is DNS first, then a certificate command. Add a CNAME record from the subdomain to the service's default *.shuttle.app address, with the proxy disabled when the registrar is Cloudflare, because the certificate check needs to see the real Shuttle address. For an apex domain, add A records pointing at the IP addresses that the default Shuttle address resolves to, which can be found with a DNS lookup:
dig +short A my-axum-app-0000.shuttle.app
Then add the certificate with the Shuttle CLI:
shuttle certificate add api.example.com
The command issues the certificate and enables HTTPS for the domain. Once it is issued, traffic to the custom domain is served by the same service as the default address, and the default address keeps working alongside it. Both names reach the same app.
The App Side of HTTPS
The app needs one thing for HTTPS to work correctly behind a platform proxy: it must not redirect on its own. The platform already redirects plain HTTP to HTTPS, and the app only ever receives plain HTTP from the platform's edge, so an app that redirects every plain request to HTTPS would redirect forever, because from the app's point of view every request is plain. The platform's redirect is the only redirect. The app answers whatever arrives, on its plain internal port, and trusts the platform to have handled the encryption.
That trust has one more detail. When the app builds a full URL for a response, such as a redirect or a link in a page, it should use the address the visitor typed, not the internal one. Platforms forward the original scheme and host in the X-Forwarded-Proto and X-Forwarded-Host headers, and frameworks that build URLs from those headers get the right answer. A plain Axum handler that returns a fixed string or a relative redirect never needs those headers at all, which is one more reason to keep responses simple.
Never Redirect to HTTPS Inside the App:
An app behind a TLS-terminating platform that redirects plain HTTP to HTTPS creates a redirect loop: the platform forwards plain HTTP, the app redirects to HTTPS, the platform terminates it and forwards plain HTTP again, and the browser spins until it gives up. The redirect belongs in the platform's settings, never in the app's handlers.
Checking the Domain
Four checks, in order, confirm a custom domain setup. The first is DNS, which proves the name points at the platform:
dig +short A api.example.com
nslookup api.example.com
The second is the certificate, which proves the platform issued one for the name:
curl -sI https://api.example.com
A 200 answer with no certificate warning means the certificate is valid and the name matches. A certificate warning in a browser, or a curl error about the certificate, means the certificate is for a different name, or it has not been issued yet.
The third is the redirect, which proves plain HTTP goes to HTTPS:
curl -sI http://api.example.com
HTTP/1.1 301 Moved Permanently
Location: https://api.example.com/
A 301 redirect to the HTTPS address is the right answer. A 200 answer over plain HTTP means the redirect is not turned on. The fourth is the app itself, which proves the domain reaches the right service:
curl https://api.example.com/health
OK
When all four pass, the domain is done. When the first fails, the DNS records are wrong or have not spread. When the second fails, the certificate is missing or for the wrong name. When the third fails, the redirect setting is off. When the fourth fails, the domain points at the wrong service.
Working Setup:
If dig shows the platform's records, curl https:// answers without a certificate warning, curl http:// returns a 301 to the HTTPS address, and the health route answers OK on the custom domain, the setup is complete. The name, the certificate, the redirect, and the app all agree, and the platform renews the certificate before it expires.
Common Beginner Mistakes
Adding a CNAME at the apex
# Wrong - DNS does not allow a CNAME at the bare domain
CNAME example.com -> my-axum-app.fly.dev
The DNS rules forbid a CNAME record at the apex, because the apex must also hold other records, and a CNAME forbids siblings. The fix is A and AAAA records for the apex, and a CNAME only for subdomains.
Getting a certificate for one name and expecting it to cover another
A certificate for example.com does not cover www.example.com, and the browser shows a warning for the name that is missing. The fix is a certificate for each name, and a redirect from one to the other so visitors land in one place.
Checking the certificate before DNS has spread
DNS changes take time, and a certificate check run minutes after the change fails because the platform still sees the old records. The fix is patience: wait, check the DNS with dig, and only then check the certificate. The platform's own check command can be run again after waiting, and it reports the records it actually sees, which is the fastest way to tell whether the problem is DNS or the certificate.
Redirecting to HTTPS inside the app
An app behind a TLS-terminating platform that redirects plain HTTP to HTTPS loops forever, because the platform always forwards plain HTTP to the app. The fix is to remove the redirect from the app and use the platform's setting, such as force_https on Fly.io.
Forgetting the redirect entirely
Without a redirect, both http:// and https:// work, and visitors who type the plain address get an unencrypted connection. The fix is the platform's redirect setting, and the check is the curl -sI http:// call above, which should return a 301 to the HTTPS address.
Final Complete Example
Here is the whole setup for one domain on Fly.io, the platform with the most commands, with the Render and Shuttle equivalents beside it. The app code does not appear here, because it does not change.
# 1. Point DNS at the app (at the registrar)
CNAME api.example.com -> my-axum-app.fly.dev
# 2. Ask Fly.io for a certificate
fly certs add api.example.com
fly certs show api.example.com
# 3. Enforce HTTPS in fly.toml
[http_service]
internal_port = 3000
force_https = true
# 4. Deploy and check
fly deploy
curl -sI http://api.example.com
curl https://api.example.com/health
# Render equivalent - dashboard only, no commands
# Settings -> Custom Domains -> add api.example.com
# Add the CNAME Render shows, then wait for the certificate
curl https://api.example.com/health
# Shuttle equivalent
# CNAME api.example.com -> my-axum-app-0000.shuttle.app
shuttle certificate add api.example.com
curl https://api.example.com/health
Run the checks in order, DNS first, certificate second, redirect third, app fourth, and the first check that fails names the step that needs fixing.
Summary
A custom domain is three separate jobs that look like one: a name that points at the app, a certificate that proves the app owns the name, and a redirect that makes the encrypted address the only one. Each job has its own check, and each check fails in its own way, which is why the order matters. DNS first, because the certificate check reads it. Certificate second, because the redirect is meaningless without it. Redirect third, because it is the step that makes HTTPS the default rather than an option.
The decision framework is short. Own the domain, point it with the records the platform shows, let the platform issue and renew the certificate, and never handle TLS in the app. The app's job is to answer requests on a plain port and to stay out of the redirect business. Everything else, the name, the lock, and the redirect, belongs to the platform, and the platform does it the same way whether the app is on Fly.io, Render, or Shuttle.