How to Connect Your Own Domain to a Next.js Site
A practical walk-through for pointing a custom domain at a Next.js app, from adding the domain on your host to DNS records, HTTPS and redirects.
10 min readUpdated Nov 27, 2026By XPASS Editorial Team

You have built a Next.js site, it runs on a temporary address that your host gave you, and now you want people to reach it at your own name. Connecting a domain sounds like one task, but it is really four small ones: tell your host which domain to serve, point the domain's DNS records at that host, let the host issue an HTTPS certificate, and decide how the www and bare versions of the name should behave.
This guide walks through those steps in the order you will meet them. It stays general on purpose, because Next.js can run on a managed platform, in a container, or on a server you manage yourself, and each host uses slightly different wording. If you are still choosing a name, the domain search page is the place to check availability first. If you have used a different site builder before, the sister guides for Squarespace and Framer show how the same ideas look there.
What "connecting a domain" really means
A domain name is a label. By itself it does not host anything. When someone types your name into a browser, the browser asks the Domain Name System for the IP address (or another name) that the label points to, then opens a connection to that address and asks for the page. The rules for how names and records work are old and stable; the original description is in RFC 1034.
So connecting a domain to Next.js means making two systems agree:
- The DNS records must lead visitors to the machine or platform that runs your app.
- That machine or platform must know that requests for your domain belong to your app, and it must be able to answer over HTTPS with a certificate that matches the name.
If either side is missing, you get one of the familiar failures: a "site can't be reached" page when DNS is wrong, a "not found" page from the host when the domain was never added, or a certificate warning when HTTPS has not been issued yet.
Nothing in this process changes your code. A Next.js app does not store its own domain name in any special place. You may refer to the public address in environment variables, in metadata and in canonical tags, but the connection itself lives in DNS and in the host's settings.

Step 0: Know where your app runs
The exact clicks depend on where Next.js is deployed. The table groups the common setups by what you will be asked to do.
| Where the app runs | What the host asks for | Who issues HTTPS |
|---|---|---|
| Managed platform for front-end frameworks | Add the domain in the project settings, then create the DNS records it shows you | The platform, usually automatically |
| Container service or app platform | Add a custom domain to the service, then create a CNAME or A record | The platform, usually automatically |
| Your own server or virtual machine | Point an A record (and AAAA for IPv6) at the server, then configure a reverse proxy | You, with a certificate authority tool, or a certificate you install |
| Static export hosted on a file or object store | A CNAME or ALIAS record to the storage or CDN hostname | The CDN or storage front end |
If you are not sure which row applies, open your deployment settings and look for a section called Domains, Custom domains or something similar. A managed host will have it. A plain server will not, and you will work with a web server such as Nginx or Caddy instead.
Write down two things before you begin: the exact domain you want to use (for example example.com and www.example.com) and the values your host tells you to use for DNS. Hosts print these in their domain screen, and they are specific to your project, so copy them rather than reusing values from a tutorial.
Step 1: Add the domain on your host
On a managed platform, open the project, find the domain settings, and add your domain. Add both the bare domain and the www version if you want both to work. Most platforms then show a status such as "invalid configuration" or "pending", together with a list of DNS records they expect. Leave that screen open; it is your checklist.
Two choices matter at this point:
- Which version is the main one. Pick either example.com or www.example.com as the primary address and let the other redirect to it. Search engines treat the two as different sites unless you tell them otherwise, and a single primary address keeps links, analytics and certificates simple.
- Whether to let the host manage your DNS. Some platforms offer to take over your nameservers. That is convenient, but it moves all your DNS records, including email records, to a new place. If you only want the website to move, keep your current DNS service and add the records by hand.
On a server you manage, the equivalent step is to add a server block or site entry for the domain in your reverse proxy, forwarding requests to the port where the app listens, which is port 3000 by default for the Next.js production server. Keep that in mind for later, because the proxy is also where HTTPS is configured.
Step 2: Create the DNS records
Open the DNS settings for your domain at your registrar or DNS provider. If you registered the name with us, the DNS editor is part of the domain management area described on the domains page.
A typical setup looks like this, using the documentation address 203.0.113.10 as a stand-in:
| Name | Type | Value | Purpose |
|---|---|---|---|
| @ (the bare domain) | A | 203.0.113.10 | Send example.com to the host's address |
| www | CNAME | the hostname your host provides | Send www.example.com to the host |
| @ | AAAA | the IPv6 address, if your host gives one | Optional, for IPv6 visitors |
Use the real values from your host, not the example ones. A few rules explain why the table looks the way it does:
- A CNAME record says "this name is an alias of that name". The standard does not allow a CNAME at the same name as other records, and the bare domain always carries other records such as SOA and NS. That is why the bare domain normally uses an A record, or an ALIAS or ANAME record if your DNS service offers one that flattens the alias into addresses.
- If an old A or CNAME record for the same name already exists, edit or delete it. Two conflicting records for one name cause intermittent behaviour, where some visitors reach the old site and some reach the new one.
- The TTL value controls how long other resolvers may cache the answer. A lower value, such as a few minutes, makes later corrections take effect sooner. You can lower it before a migration and raise it again afterwards.
- Do not touch MX, TXT or other records you did not intend to change. They belong to email and verification, not to the website.
Save the records, then return to the host's domain screen and use its refresh or verify button if there is one.
Step 3: Wait, verify and issue HTTPS
DNS changes are not instant. Resolvers around the world cache answers for up to the previous TTL, so the new records appear gradually. In practice many changes are visible within minutes, but plan for a few hours.
You can check the result yourself instead of waiting blindly:
- Run a lookup with a tool such as dig or nslookup for example.com and www.example.com, and compare the answers with what your host expects.
- Try the lookup against a public resolver as well as your default one, to see whether caches differ.
- Open the host's domain screen. Most platforms re-check automatically and flip the status to valid.
Once the host sees the records, it requests a certificate for your name. The process is usually automatic and based on the ACME protocol used by certificate authorities such as Let's Encrypt; the overview in How It Works explains the challenge that proves you control the name. If you want a certificate you choose and manage yourself, for example one that includes your company details, read about the options on the SSL page. Either way, the certificate must list the exact names you serve.
On your own server, this step is yours. Install a certificate with a tool that supports ACME, configure the reverse proxy to use it, and set up automatic renewal so it does not expire quietly. The background on what HTTPS adds is covered in What is HTTPS?.
Step 4: Decide how www and the bare domain behave
After the certificate is in place, make sure both names end up in the same place. There are two common approaches:
- Redirect at the host. Most managed platforms let you mark one domain as a redirect to the other with a permanent status. This is the simplest option and needs no code.
- Redirect in Next.js. You can declare redirects in the framework configuration, matching on the host header and sending visitors to the primary address. This is useful when your host does not offer a redirect switch.
Either way, use a permanent redirect so search engines learn which address is canonical, and test both versions in a private browser window after the change. Also test a deep link, not only the home page, to confirm the path is preserved.
Then update the places inside your project that mention the public address:
- A site URL environment variable, if your code reads one for absolute links.
- The metadata base and canonical URL settings, so that page tags use the primary address.
- Sitemap and robots output, if you generate them, so they list the new name rather than the temporary address.
- Any third-party sign-in or payment callback URLs that were registered against the old address.
Redeploy after changing environment variables, because Next.js reads many of them at build time.

Keep your email working
Moving the website must not interrupt email, and it usually will not if you only edit website records. Mail delivery uses MX records, and sender checks use TXT records for SPF, DKIM and DMARC. None of these appear in the table above, so leave them alone.
The risk appears in two situations. The first is when you change nameservers to a new DNS provider: the new zone starts empty, and email stops until you recreate every MX and TXT record. Export or screenshot the existing zone before you switch. The second is when a platform offers a one-click setup that replaces records. Read what it will change before you accept.
If you do not yet have mailboxes on your domain, the business email page explains what a hosted mailbox setup involves, and it is worth planning the DNS for it at the same time as the website.
Limits and what to watch for
Most problems on this journey fall into a short list.
- Propagation confusion. The site works on your phone and not on your laptop, or the reverse. That usually means two caches hold different answers. Wait, clear the local DNS cache, or test from another network.
- Wrong record type. A CNAME on the bare domain is rejected by many providers, and a bare A record where the host wanted a CNAME may work today and break when the host changes its addresses. Follow the host's instructions for each name.
- Leftover records. An old A record for www that you forgot about will compete with the new CNAME. Remove whatever you no longer need.
- Proxying and CDN layers. If your DNS provider has an orange-cloud style proxy mode, it can interfere with the host's certificate check. Switch it off until the certificate is issued, then follow the host's advice about turning it back on.
- HTTPS-only policies. Once you tell browsers to always use HTTPS for a name, mistakes become harder to undo. Add strict policies only after both names work and certificates renew correctly.
- CAA records. If your zone contains CAA records restricting which certificate authorities may issue, make sure the authority your host uses is allowed, or issuance will fail.
- Redirect loops. A redirect configured at both the host and the CDN or code can send the browser in circles. Keep the redirect in a single place.
- Domain renewal. A connected site still disappears if the registration expires. Turn on renewal reminders or auto-renew with your registrar.
When something fails, work from the outside in. First check that the name resolves to the expected address. Then check that the host recognises the domain. Then check the certificate. Changing several things at once makes the cause harder to find.
A short worked example
Imagine a small design studio with the domain studiohana.example. Its Next.js site is deployed on a managed platform and shows the studio's pages on a temporary address.
- In the platform's project, the owner adds studiohana.example and www.studiohana.example, and sets the bare domain as primary.
- The platform shows an A record value for the bare domain and a CNAME target for www.
- At the DNS provider, the owner edits the existing A record for the bare name, replaces the old www record with the new CNAME, and leaves the MX and TXT records for email as they are.
- After ten minutes, the platform's status turns valid and it issues the certificate.
- The owner opens both names in a private window, confirms that www redirects to the bare domain, and updates the site URL environment variable and canonical tags, then redeploys.
- A week later, a calendar reminder for the domain renewal fires, and the owner confirms the registration is set to renew.
Nothing about the code changed, and email kept working throughout, because only website records were edited.
Summary
Connecting a domain to Next.js is a matter of agreement between three things: the host must know the name, DNS must point to the host, and a certificate must match the name. Add the domain on the host first, copy the exact DNS values it gives you, create an A or ALIAS record for the bare domain and a CNAME for www, wait for the records to be visible, and let HTTPS issue. Then choose one primary address, redirect the other, update your site URL settings and redeploy. Leave MX and TXT records alone so email keeps flowing, and watch for leftover records, proxy layers and expiring registrations.
If you want to register a name or move one in, the domains page is a good place to start.
Frequently asked questions
Do I need a special domain to use with Next.js?
No. Any domain you control can point at a Next.js app. What matters is that you can edit its DNS records, either at your registrar or at the DNS service you delegate to.
Should I use an A record or a CNAME record?
For the bare domain such as example.com, most hosts ask for an A record, or an ALIAS or ANAME record if your DNS service supports it. For www.example.com they usually ask for a CNAME that points to a hostname the host gives you.
Why does my site show a certificate warning right after I connect the domain?
Most hosts issue the HTTPS certificate only after the DNS records are visible to them. Until that check passes, the browser may show a warning. Wait for propagation, confirm the records are correct, and the certificate normally appears on its own.
Will changing DNS for my website break my email?
It can if you replace the whole zone or change nameservers without copying the MX and TXT records. Adding or editing only the A and CNAME records for the website leaves email records untouched.
How long does it take for the domain to start working?
Often minutes, sometimes a few hours, depending on the TTL of the old records and on caches along the way. Check the records with a lookup tool rather than guessing.
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 a Custom Domain to Squarespace
A clear walkthrough for pointing a domain bought elsewhere at your Squarespace site: preparation, DNS records, www and root, email safety and final checks.
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

Website Guides
How to Connect a Custom Domain to Framer
Connecting your own domain to a Framer site comes down to a few DNS records and one decision about www. Here is the full process, from preparation to verification.
10 min read