Skip to content

Getting a Next.js site onto a custom domain is two jobs that people often treat as one. DNS decides where visitors are sent. HTTPS decides whether the connection is encrypted and whether the browser believes it is talking to the right owner of that name. A site can have perfect DNS and no certificate, or a perfect certificate and a name that points nowhere.

This guide focuses on those two layers: the records you create, how the certificate is obtained and renewed, and how to verify the result with tools you already have. It assumes the application already runs somewhere and that you can edit the domain's records. If you still need a name, begin on the domains page. If you build other kinds of sites, the same ideas appear in the matching guides for Squarespace, React and Framer.

How a request reaches a Next.js app

Follow one visit from start to finish.

  1. The browser asks a DNS resolver for the address of your name. The resolver walks from the root down to your domain's authoritative nameservers and returns the records, as described in RFC 1035.
  2. The browser connects to the returned address and starts a TLS handshake, asking for your name with the server name indication field.
  3. The server presents a certificate. The browser checks that it names your domain, that it is within its validity dates and that it chains to an authority the browser trusts. The handshake itself is defined in TLS 1.3.
  4. The encrypted channel opens, and the browser sends an HTTP request.
  5. Something terminates TLS: the hosting platform, a CDN, a load balancer, or your own Nginx or Caddy. It forwards the request to the Next.js process, which usually listens on a local port such as 3000.

Notice that Next.js appears only at the very end. Everything before it is DNS and TLS, which is why most "my domain does not work" problems are solved without touching application code.

The DNS records a Next.js site uses

Here is the small set of record types that matter, and what each does for a website.

Type Name What it does Typical use for Next.js
A @ or a subdomain Maps a name to an IPv4 address Bare domain to a server or platform address
AAAA @ or a subdomain Maps a name to an IPv6 address Optional IPv6 support
CNAME usually www Makes one name an alias of another www to the hostname your host provides
ALIAS or ANAME @ Alias at the bare domain, resolved by the DNS provider Bare domain to a hostname when no fixed IP is given
CAA @ Lists which authorities may issue certificates Optional restriction for issuance
TXT varies Plain text, used for verification and email policy Domain ownership checks requested by a host
MX @ Mail servers for the domain Not part of the website, leave unchanged

Three habits prevent most mistakes. First, copy the values your host shows instead of using values from a tutorial; platforms change their addresses and targets over time. Second, give each name one clear answer: a CNAME cannot coexist with other record types at the same name, so remove the old record before adding the new one. Third, keep a copy of the zone before you change anything, so you can undo a mistake quickly.

The TTL, expressed in seconds, controls how long resolvers may keep an answer. If you plan a change, lowering the TTL a day ahead makes the change take effect sooner. Raising it again afterwards reduces unnecessary lookups.

Who handles HTTPS in your setup

The place where TLS ends determines how you obtain the certificate.

  • Managed platform. You add the domain, create the records, and the platform asks a certificate authority to issue a certificate for you. It also renews it. Your job is to keep the DNS records correct and to avoid blocking validation.
  • CDN or proxy in front. The CDN presents its own certificate to the browser and talks to your origin separately. You need a valid certificate on each leg, or a mode that you consciously accept as weaker.
  • Your own server. You request a certificate, install it in the web server or reverse proxy, and arrange renewal. Many people use an ACME client for this, because the protocol in RFC 8555 automates the proof of control and issuance.

If you want a certificate with specific validation, a particular name coverage such as a wildcard, or one that you manage as part of a company policy, compare the options offered by certificate providers before you decide. For the background on why encryption matters for ordinary visitors, What is HTTPS? is a readable introduction.

Step by step: managed platform

  1. In the project settings, add the bare domain and the www version. Choose which one is primary.
  2. Read the records the platform asks for. Note the type, the name and the value for each.
  3. In your DNS provider, create or edit those records. Remove stale records on the same names. Do not alter MX or TXT records that belong to email.
  4. Return to the platform and trigger a re-check if there is a button for it.
  5. Wait for the status to turn valid, then for the certificate to be issued. This can take from a few minutes to some hours.
  6. Open both names over HTTPS in a private window and look at the padlock details to confirm that the certificate lists your domain.
  7. Confirm that plain HTTP redirects to HTTPS and that the non-primary name redirects to the primary one.

If step 5 stalls, the usual cause is a record that does not match what the platform sees from the public internet. Query your records from outside your own network and compare them with the instructions.

Step by step: your own server

On a server you control, the arrangement looks like this.

  1. Run the production build of Next.js and keep it running under a process manager, listening on a local port.
  2. Install a reverse proxy such as Nginx or Caddy to receive public traffic on ports 80 and 443.
  3. Create an A record for the bare domain (and AAAA if you have an IPv6 address) pointing to the server, and a record for www.
  4. Make sure port 80 is reachable from the internet, because many validation methods use it.
  5. Request a certificate for both names with an ACME client, and let it write the certificate files and reload the proxy.
  6. In the proxy configuration, send requests for your domain to the local port and pass the original host and protocol so the app knows how it was reached. The proxy should set the forwarded protocol header, commonly called X-Forwarded-Proto.
  7. Redirect port 80 to HTTPS, and redirect the non-primary name to the primary name.
  8. Test renewal in a dry run, and confirm that a scheduled job or timer exists for it.

Caddy handles much of this automatically for names it can validate; Nginx needs the certificate paths in its server block. Whichever you choose, keep the firewall open on both ports for the validation window.

Redirects and headers that belong with HTTPS

Once the certificate works, a few settings make the site behave consistently.

  • HTTP to HTTPS. Anyone who types the bare name without a scheme may start on HTTP. A permanent redirect sends them to the secure address. Configure it at the platform or proxy.
  • One primary host. Pick either the bare domain or the www name and redirect the other. Use a permanent redirect so search engines consolidate signals.
  • Canonical and metadata settings. In Next.js, set the metadata base and canonical URLs to the primary HTTPS address so page tags and generated absolute links match.
  • Forwarded headers. Behind a proxy, the app sees a local connection. If it builds absolute URLs, sets secure cookies or enforces redirects, it needs the forwarded protocol and host headers to know the visitor used HTTPS.
  • Secure cookies. Mark session cookies as secure so they travel only over HTTPS. Check that your authentication library trusts the proxy headers.
  • HSTS. The Strict-Transport-Security header tells browsers to use HTTPS for your domain for a period you specify. It is helpful and also unforgiving: if your certificate lapses while HSTS is active, browsers refuse to let users click through. Enable it with a short period first, and extend it after you have confirmed renewal works.
  • Mixed content. If a page loaded over HTTPS references images, scripts or frames over HTTP, browsers block or warn. Search your code and content for hard-coded http addresses.

Verify with simple tools

You do not need specialist software to check the result.

Check How What good looks like
DNS answers dig or nslookup for the bare name and www Values match your host's instructions
Public view Query a public resolver, not only your default Same answers as above
Certificate Open the padlock details in the browser, or use a command-line TLS client Names include both versions, valid dates, trusted issuer
Redirects curl with the headers-only option against each URL HTTP goes to HTTPS, non-primary goes to primary, each with a permanent status
Headers Look at the response headers Expected security headers present once, not duplicated
Renewal Dry run of your ACME client, or the platform's status page No errors, a visible next renewal date

Run these checks in order. DNS first, because TLS cannot succeed against the wrong address; then the certificate; then redirects.

Limits and what to watch for

  • Caching hides your fix. Browsers, operating systems and resolvers cache answers. If a correction seems to have no effect, test from another network or wait out the old TTL.
  • Validation blocked. Firewalls, geo rules, or redirects on the validation path can stop a certificate request. Allow the validation path while issuing.
  • Proxy mode conflicts. When a DNS provider offers its own proxy mode, certificates issued at the origin may fail to validate until you pause it, or your origin certificate type may need to match the proxy setting.
  • Wrong certificate name. A certificate for the bare domain does not automatically cover www. Check that both are listed, or use a wildcard where appropriate.
  • CAA surprises. An old CAA record can silently block the authority your host uses. If issuance fails with no clear error, look at CAA first.
  • Expiry. Certificates have limited lifetimes by design. Automatic renewal is the answer, but it breaks if DNS records change or the validation path is closed later. Calendar a check.
  • Domain expiry. A valid certificate cannot save a lapsed domain registration. Keep the registration current.
  • Email side effects. Changing nameservers or replacing the entire zone can remove MX and TXT records. Copy them first. If you plan mailboxes, see how the domains page fits with email setup.

A worked example

Take a small shop that runs its Next.js storefront on a virtual machine behind Nginx. The shop's domain is mintbakery.example.

  1. The developer creates an A record for the bare domain pointing to the VM's address, a CNAME for www pointing to the bare domain, and leaves the existing MX and TXT records alone.
  2. Port 80 and 443 are opened on the VM firewall.
  3. An ACME client requests a certificate for mintbakery.example and www.mintbakery.example and writes the files. Nginx is reloaded.
  4. The Nginx server block sends HTTP to HTTPS, sends www to the bare domain, and proxies HTTPS requests to the app on port 3000 with the forwarded protocol header set.
  5. In the Next.js project, the metadata base is set to the bare HTTPS address, and secure cookies are enabled.
  6. The developer checks with curl that each variation ends at the same final address with a permanent redirect, and runs a dry run of the renewal command.
  7. A monthly reminder checks the expiry date and the next scheduled renewal.

The result is a boring site, which is exactly what you want from DNS and HTTPS.

Summary

For a Next.js site, DNS tells browsers where to go and HTTPS proves they arrived at the right place. Create the minimal records your host asks for, keep email records untouched, and let a platform or an ACME client issue and renew the certificate. Decide where TLS ends, pass the forwarded headers to the app, redirect HTTP to HTTPS and non-primary names to the primary one, and test from outside with dig, curl and the browser. Treat HSTS, CAA, proxy modes and expiry as the places where good setups quietly go wrong.

When you are ready to register or transfer the name that will carry the site, the domains page is where to begin.

Frequently asked questions

Which DNS records does a Next.js site need?

At minimum, a record that sends the bare domain to your host (an A record or an ALIAS-style record) and a CNAME for www. Add AAAA if your host gives an IPv6 address, and optionally a CAA record to limit which authorities may issue certificates.

Who issues the HTTPS certificate for my Next.js app?

On a managed platform, the platform normally requests and renews it for you. On your own server, you install a certificate yourself, often with an ACME client, and configure the web server or reverse proxy to use it.

Does Next.js handle HTTPS itself?

The Next.js production server speaks plain HTTP. In most setups the platform, a reverse proxy or a load balancer ends the HTTPS connection and forwards requests to the app.

Why do I get a redirect loop after enabling HTTPS?

Usually two layers are both redirecting, or the app cannot tell that the original request was already HTTPS because the proxy does not pass the forwarded protocol header. Keep the redirect in one place and pass the header.

How do I know the certificate will renew?

Check the expiry date regularly, confirm that automatic renewal is configured and that the validation path stays reachable. On a managed host, watch for notices about failed renewals.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

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

Ready to register your domain?

Search a name, compare extensions and pay once for the years you choose.

.com registration from $18.81 for the first year

Search domains

Keep reading

Domain & DNS Guides

DNS and HTTPS Setup for Squarespace: What You Need to Do

What sits underneath a Squarespace domain: the DNS records involved, how HTTPS certificates are issued and renewed, redirects, caching and common errors explained.

10 min read

Domain & DNS Guides

How to Set Up DNS and HTTPS for a React App

A practical guide to DNS records, HTTPS certificates, API subdomains and headers for a React single-page app on its own domain.

10 min read

Domain & DNS Guides

DNS and HTTPS Setup for Framer: What You Need to Do

A practical look at the DNS records and HTTPS behaviour behind a Framer site: record types, certificate issuance, redirects, caching and how to fix typical errors.

10 min read