How to set a custom URL for an Azure Static Web App
This site runs on Azure Static Web Apps on the Free plan. Out of the box,
Azure hands you an autogenerated address like
black-pond-097a9a910.7.azurestaticapps.net. That works, but it isn’t the name
you want on a business card. Here’s how I point a real domain at it — and the
good news is Azure issues and renews free SSL/TLS certificates for every custom
domain you add, so you get HTTPS for nothing.
There are two cases worth knowing: the www subdomain and the apex (root)
domain. Most people want both.
First, know your two names
Given www.example.com:
wwwis the subdomain.example.comis the apex (or root) domain.
They’re configured differently because of how DNS works: a CNAME record maps a
name to another name (great for www), while the apex generally can’t use a
plain CNAME and needs an ALIAS/ANAME record, CNAME flattening, or an
A record.
Setting up the www subdomain (CNAME)
This is the simplest path and works with almost any registrar.
-
In the Azure portal, open your static web app and copy the generated URL from the Overview pane.
-
Sign in to your domain registrar and open its DNS settings.
-
Add a
CNAMErecord:Setting Value Type CNAMEHost wwwValue your *.azurestaticapps.netURLTTL leave the default -
Back in the portal, go to Settings → Custom domains → + Add → Custom domain on other DNS. Enter
www.example.com, choose CNAME as the hostname record type, and select Add.
Azure verifies the record exists in public DNS, then provisions the certificate. Propagation depends on your record’s TTL and can take anywhere from a few minutes to a couple of days.
Setting up the apex domain
The apex is the fussy one. Your options, best-performance first:
ALIAS/ANAMErecord — if your registrar supports it. Keeps you on Azure’s global distribution.Arecord — a fallback that pins you to a single regional host, so you lose global distribution. Only use it if you have to.- Azure DNS — move your domain’s DNS to Azure and it wires the apex up for
you automatically. This is the cleanest option if your registrar (looking at
you, GoDaddy and Squarespace) won’t do
ALIASrecords.
Whichever you pick, you validate ownership first with a TXT record:
- In Custom domains → + Add, enter the apex (
example.com, no subdomain), choose TXT as the hostname record type, and select Generate code. - Copy the generated value and add it at your registrar as a
TXTrecord with host@. - Once Azure validates ownership, add the
ALIASrecord (host@, value = yourazurestaticapps.netURL without thehttps://prefix). For theA-record path, grab thestableInboundIPfrom the portal’s JSON View and point anArecord at it instead.
Apex changes can take up to 72 hours to fully propagate, so don’t panic if it isn’t instant.
Don’t forget the site config
One thing that’s easy to miss: your generator needs to know its real address so
canonical URLs and absolute links point at the right place. In Astro that’s the
site field in astro.config.mjs:
import { defineConfig } from 'astro/config';
export default defineConfig({
site: 'https://www.example.com',
});
Update it, commit, and let CI redeploy.
A couple of gotchas
- Custom domains aren’t supported on preview environments — only the production site.
- Unicode / Punycode domains (the
xn--prefix) aren’t supported. - Migrating a live domain? Validate ownership with a
TXTrecord before you flip theCNAME/Arecord, so you can move traffic with zero downtime.
That’s the whole thing. Free hosting, free HTTPS, and a name that’s actually yours.