How to Connect Your Own Domain to an Astro Site
A practical guide to connecting a custom domain to an Astro project, covering static and server builds, DNS records, the site setting and common problems.
10 min readUpdated Nov 27, 2026By XPASS Editorial Team

Astro builds fast content sites, and by default it produces plain static files: HTML, CSS, JavaScript and images in an output folder. That makes connecting a domain simpler than for many frameworks, because the destination can be any static host, a CDN or an ordinary web server. It also means there are more choices at the start, and most problems come from mixing up which layer is responsible for what. The domain registrar or DNS host decides where the name points. The host or server decides which files to serve. The Astro project decides what absolute address it believes it has.
This guide takes you through the whole path: deciding how the site is built and hosted, adding DNS records, telling Astro its final address, handling redirects and trailing slashes, and checking the result. It assumes a project that already builds without errors. If you want to see how a similar job looks for a PHP back end, connecting a domain to Laravel shows the web server side in more detail, while connecting a domain to Ghost and connecting a domain to React cover a publishing platform and a single-page app. To find or register a name, see the domains page.
Decide how the site is built and hosted
Astro offers two broad output styles, and the choice determines what you need to host.
| Output style | What the build produces | What you need to host it |
|---|---|---|
| Static (the default) | A folder of ready-made files, usually called dist | Any static host, CDN or web server that can serve a folder |
| Server rendered, with an adapter | Code that runs on a server or in a serverless function | A host that runs that adapter, or a Node server you manage behind a web server |
| Hybrid | Mostly static pages, some rendered on demand | Same as server rendered, since some routes need code to run |
If your pages do not change per visitor, static output is usually the simplest and most robust: no process to keep running, no memory to monitor, and any web server can serve it. Choose a server adapter only when you need things like per-request rendering, login-dependent content or API routes that run on your own infrastructure.
Then choose where the files go. Options include a static hosting service with Git integration, object storage with a CDN in front, a virtual private server running Nginx or Apache, or a managed hosting plan with a panel. Each of them gives you one of two things to point DNS at: an IP address or a hostname. Write that down, because the DNS step depends on it.

How a domain reaches your Astro site
The path is the same as for any website, as described in RFC 1034 and summarised in Cloudflare's DNS explainer.
- A visitor types the domain, and their device asks a DNS resolver for its address.
- The resolver follows the domain's name servers and returns the address from your records.
- The browser connects to that address and asks for the page, naming the domain in the request.
- The host or web server picks the site that matches that name and returns the right file or runs the server code.
DNS only handles step 2. Steps 3 and 4 need the host to know that your domain belongs to your site. On a managed static host, you do this by adding the domain in its dashboard. On your own server, you do it with a virtual host entry. Skipping that is the most frequent reason a correct DNS record still shows a default page or an error.
Step 1: Add the DNS records
Open the DNS settings for your domain and add what your host asks for. Use this table to translate instructions into records.
| Your host gives you | Root domain | www |
|---|---|---|
| An IPv4 address | A record with that address | CNAME to the root domain, or another A record |
| An IPv6 address as well | Add an AAAA record with it | Same pattern |
| A hostname | ALIAS, ANAME or flattened CNAME if your DNS provider offers it; otherwise follow the host's guidance | CNAME to the hostname |
| Custom name servers to use instead | Change the name servers at the registrar, and manage records at the host | Managed at the host |
Some points to keep in mind. Do not leave old records from a previous host or a parking page in place, because two competing answers send visitors to different places. Add an AAAA record only if the host explicitly provides IPv6. If you plan to use email on the same domain, keep the mail records intact; the business email page explains that product. Setting a moderate TTL during the work helps you correct mistakes quickly, and you can raise it afterwards.
After saving, query the records from outside your own network with dig, nslookup or an online lookup tool. If you still see the old answer, wait for the earlier TTL to expire instead of making repeated changes.
Step 2: Add the domain at the host
For a managed static host, open the project settings, find the custom domain section and add both the root and www names. The host will usually show which records it expects and will mark the domain as verified once DNS matches. It may also issue a certificate for you automatically after verification.
For your own server with Nginx, create a server block whose server_name lists the root and www names and whose root points at the folder that holds your build output. Use try_files so that a request for a path serves the matching file or the matching folder index, and add an error page that points at the built 404 file. For a server-rendered build that runs as a Node process, run it on a local port with a process manager and configure Nginx as a reverse proxy to that port, forwarding the Host header and the original protocol. Remember to copy the new build output to the server after each deployment, and keep the old build in place until the new one is complete.
If the site needs HTTPS, which in practice it does, add a certificate once the name resolves. The SSL page describes the options, and the mechanism that automated authorities use is explained in Let's Encrypt's overview. After that, add redirects from http to https and from the non-canonical host to the canonical one.
Step 3: Tell Astro its final address
Astro cannot guess your public address. The site option in the astro.config file should be set to the final address, for example https://example.com. Astro then uses it to produce canonical link tags, absolute URLs in feeds and the sitemap integration's output. If you leave it empty or at a staging address, search engines will receive pages that point to the wrong place.
Check these related settings at the same time.
- base: this is only for sites that live in a subfolder of a domain. If you used it for a project page on a Git hosting service, remove it when you move to a dedicated domain, or every asset path will carry a prefix that no longer exists.
- trailingSlash and build.format: these decide whether pages are built as folders with an index file or as plain files, and whether URLs end with a slash. Make the web server's behaviour match. A mismatch is a common reason for redirect loops or 404 errors on pages that exist.
- Environment variables: public variables that hold URLs, such as an API address or analytics endpoint, may point to development values. Review them before the production build.
- Sitemap and robots: the sitemap integration relies on the site option. The sitemap format is described by the Sitemaps protocol. Make sure the robots file refers to the sitemap at the final address.
Rebuild after any change to these options, since they are applied at build time for static output.
Step 4: Redirects, HTTPS and checks
When the domain loads, tidy up the address space so that there is one canonical version.
- Redirect http to https with a permanent redirect.
- Redirect the non-canonical host (root or www) to the canonical one.
- Test combinations: http with and without www, https with and without www. Each should end on the same single address after at most one redirect.
- Open a deep page directly, not just the home page, and reload it. Static hosts that mishandle trailing slashes show their problems here.
- Open the page source and confirm that the canonical tag and Open Graph URLs show the final domain.
- Check images, scripts and fonts in the browser console for mixed content or 404 responses.
If the site has a contact form or other server features, remember that static output cannot run server code by itself. Forms need an external form service or an API route in a server build.

Troubleshooting
| Symptom | Likely cause | What to check |
|---|---|---|
| Domain not found | Record missing or not updated yet | Query DNS from outside your network; verify the right zone |
| Host's default or parked page appears | Domain not added at the host, or old records remain | Host dashboard and old A or CNAME records |
| Certificate warning | Certificate not issued yet, or does not include the www name | Names on the certificate and the host's verification status |
| Home page works, other pages 404 | Trailing slash or file format mismatch, or wrong output folder | Build format settings and the server's try_files rule |
| Styles and scripts missing | Base path set for a subfolder, or wrong asset address | The base option and the network tab in the browser |
| Canonical or sitemap shows another domain | The site option is wrong | astro.config, then rebuild and redeploy |
| Redirect loop | Two layers both force a redirect, such as a CDN and the origin | Disable one rule and test each layer separately |
Limits and what to watch for
- Static means no server code. Features such as login, per-user pages or form handling require a server build or an external service.
- Caches hide changes. Browser, CDN and DNS caches all keep older answers for a while. Test in a private window and, where possible, check the host's cache or purge option.
- The site option is not optional in practice. Sitemaps, feeds and canonical links depend on it, and mistakes there can confuse search engines for months.
- Keep records for mail. Editing the DNS zone for the website must not remove mail records if the domain is used for email.
- Domain renewal matters. An expired registration takes the site down along with anything else tied to the name. Keep contact details current and renewal reminders on.
- Staging before production. A subdomain for previews lets you test the same configuration without risking the live address.
Summary
Connecting your own domain to an Astro site takes four aligned pieces: DNS records that point the name at the right host, the host or web server told that it should answer for the name, Astro configured with its final public address, and HTTPS with a single canonical address. Static output keeps the hosting simple, while a server build adds a process to run and proxy. Test every variant of the address, read your logs when something fails, and change one thing at a time.
When you are ready to pick or register the name, the domains page is where to begin.
Frequently asked questions
Do I need a server to connect a domain to an Astro site?
Not always. A default Astro build produces static files that any static host or web server can serve. You need a running server only if you use server-side rendering with an adapter, in which case the host must run the adapter's output.
Which DNS record should I use for an Astro site?
If the host gives you an IPv4 address, use an A record for the root domain. If it gives you a hostname, use a CNAME for www, and follow the host's instructions for the root domain, since many DNS providers offer an alias type for that.
What is the site setting in astro.config for?
It tells Astro the final public address of the site. Astro uses it to build canonical URLs, sitemap entries and absolute links, so it should match the domain you chose, including https.
Why do my assets or pages return 404 after connecting the domain?
Common causes are a base path set for a project subfolder that no longer applies, a host serving the wrong output folder, or a missing trailing-slash rule that does not match how the pages were built.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Start your website the right way
Register a domain, add SSL and set up business email from one place.
.com registration from $18.81 for the first year
Start with a domainKeep reading

Website Guides
How to Connect Your Own Domain to a Laravel App
A practical walk-through for pointing a custom domain at a Laravel app, from DNS records and the public folder to APP_URL, proxy settings and troubleshooting.
10 min read

Website Guides
How to Connect a Custom Domain to Ghost
A practical walkthrough for pointing your own domain at a Ghost publication, with DNS records, redirects, email safety and a checklist of common mistakes.
10 min read

Website Guides
How to Connect Your Own Domain to a React App
A step-by-step guide to putting a React app on your own domain, covering hosting, DNS records, HTTPS, routing fallbacks and email safety.
10 min read