Skip to content

An Astro site is mostly static files, which makes HTTPS easier than it is for an application with sessions and server code. There is still a chain to get right. The domain's DNS records must point at wherever the files are served from, that place needs a certificate that covers the domain, requests on plain http must be forwarded to https, and the project itself has to know the final secure address so that canonical links, sitemaps and feeds all agree. A gap in any link of the chain produces the familiar symptoms: a browser warning, a missing padlock, or pages that load but quietly pull in insecure files.

This guide works through that chain in order and ends with a checklist. It is written for static output and mentions the extra points for server-rendered builds where they differ. Related stacks have their own guides, such as DNS and HTTPS for Laravel, for Ghost and for React. If you need to register a name first, the domains page explains how.

What HTTPS needs from DNS and from the host

HTTPS is HTTP inside a TLS connection, as Cloudflare's explainer puts it. For the connection to succeed, the server has to present a certificate that names the domain the visitor typed. A certificate is issued by an authority only after it has checked that the applicant controls the domain, and automated authorities do this with the ACME protocol described in RFC 8555.

In practice there are three common setups for an Astro site, and the one you have determines who does what.

Setup Who handles the certificate What you do
Managed static host The host issues and renews it after verifying the domain Add the domain in the dashboard, create the DNS records it asks for, wait for verification
Your own server (Nginx or Apache) You, usually with an ACME client Point DNS at the server, make the web server answer on port 80, run the client, add redirects
A CDN in front of the origin The CDN presents one certificate to visitors, and the origin may have another Configure both connections and choose a mode that verifies the origin certificate

Whatever the setup, the order is the same: DNS first, then the host or server recognising the name, then the certificate, then redirects, then the project settings.

Step 1: Create the DNS records

Records follow the formats in specifications such as RFC 1035. For a typical Astro site you need only a few of them.

  • A record for the root domain, using the IPv4 address that your host or server gives you.
  • AAAA record for the root domain only if the host explicitly provides IPv6 and you have tested it. An AAAA record that points at a machine which does not serve the site is a classic cause of a site that works for you and fails for others.
  • CNAME record for www, pointing at the root domain or at the hostname the host gives you. A CNAME cannot share a name with other records, which is why the root domain normally uses A records or a provider-specific alias type.
  • CAA record (optional) that names the authority allowed to issue certificates for your domain. If you add one, make sure it includes the authority your host or ACME client uses, or issuance will fail.
  • TXT record if the host or authority asks you to prove ownership with a token. Add it exactly as given, with no extra quotation marks beyond what your DNS screen expects.

Use a moderate TTL while you work. After saving, query the records from outside your own network with dig or an online lookup tool and confirm that both the root domain and www return what you expect. Delete leftovers from earlier hosts or parking pages so that no record contradicts another. If the domain also carries email, leave the mail records alone; the domains page is the place to start if you are managing the registration itself.

Step 2: Get the certificate in place

On a managed static host, adding the domain normally starts verification automatically. The host checks that DNS matches, then requests a certificate and attaches it. Status screens usually show pending, issued or failed. If the status stays pending for a long time, the usual causes are a DNS record that is still propagating, a leftover record that conflicts, or a CAA record that excludes the host's authority.

On your own server with Nginx, the sequence is:

  1. Confirm that the domain resolves to the server and that port 80 is open in the server and any cloud firewall.
  2. Create a server block for the root and www names that serves the folder holding the Astro build output.
  3. Run an ACME client such as Certbot or acme.sh with the Nginx plugin or webroot mode, list every name the certificate should cover, and let it validate.
  4. Check that the generated server block references the certificate and key and that the key file is readable only by the web server service.
  5. Reload Nginx and open the https address.

A wildcard certificate covers one level of subdomains and generally requires validation through a DNS record rather than through port 80. It is useful if you run many preview subdomains but unnecessary for a single site.

Step 3: Redirect http to https and pick one canonical host

A certificate makes HTTPS available. It does not make visitors use it. Add a permanent redirect from http to https at the layer that serves the site. On a managed host this is often a single setting named something like force HTTPS. On your own server, it is a small port 80 server block that returns a redirect to the same host and path on https.

Then choose between root and www as the canonical host and redirect the other one to it. All four combinations (http or https, with or without www) should end on the same single address after at most one hop. Check this with curl and read the Location headers, because browsers sometimes cache redirects and hide the real behaviour.

Astro has its own redirects option in the configuration file, which is helpful for moving one page to another path. Use it for page-level moves such as renamed articles. Leave the protocol and host redirects to the server or host, since a static page cannot redirect the connection that delivered it before it has been served.

Step 4: Tell the project its secure address

Set the site option in the astro.config file to the final https address, for example https://example.com. Astro uses it for canonical link tags, absolute URLs in feeds and the sitemap output, so a wrong value here means that search engines are told the secure site lives somewhere else. The sitemap format is described by the Sitemaps protocol, and your robots file should point at the sitemap using the final address.

Then clean up the places where insecure addresses hide.

  • Components and layouts: look for hard-coded http addresses in script, link and image tags.
  • Content files: Markdown and MDX content may include images or embeds with http addresses copied from old pages.
  • Environment variables: public variables holding API or analytics addresses should be https in the production build.
  • Third-party embeds: videos, maps and widgets should be loaded over https. If a provider offers only http, replace it.
  • Open Graph and social images: they should use absolute https addresses, or crawlers may not fetch them.

Rebuild and redeploy after changing these, because the values are baked into static output.

Step 5: Headers, HSTS and caching

Once HTTPS works everywhere, consider the Strict-Transport-Security header. It tells browsers to use only HTTPS for your domain for the number of seconds you set, which removes the first insecure request on repeat visits. Roll it out carefully.

  1. Verify that every address you use works over HTTPS, including subdomains that would inherit the policy.
  2. Start with a short max-age, such as a few minutes to a day, and check the site.
  3. Increase it gradually as confidence grows.
  4. Add includeSubDomains only when every subdomain supports HTTPS.
  5. Read the requirements before adding the preload directive, since removal takes a long time.

On a managed host, headers are usually defined in a configuration file or a dashboard setting. On Nginx, they are add_header lines in the server block. On a CDN, they are response header rules. Whichever you use, check the result with curl by requesting only the headers.

Caching deserves a mention. Static assets with hashed file names can be cached for a long time, while HTML pages should be cached briefly or revalidated, so that a fix to a redirect or a corrected link reaches visitors soon. If a CDN sits in front, clear its cache after any change that affects redirects or headers.

Checks and troubleshooting

Check How Expected result
Names resolve dig or an online lookup for root and www Both return the intended records
Certificate covers the names Click the padlock or run openssl s_client Root and www are listed, dates are valid
http redirects curl -I on the http address One permanent redirect to the canonical https address
Non-canonical host redirects curl -I on the other host Redirect to the canonical address
No mixed content Browser console on several pages No warnings about insecure resources
Canonical tag and sitemap View page source, open the sitemap Final https domain throughout
Renewal Host status or ACME dry run Reports healthy

When something fails, the table below helps you choose where to look.

Symptom Likely cause What to look at
Certificate error for the right domain Certificate not yet issued, or does not include www Host status screen or the names on the certificate
Certificate stays pending DNS still propagating, conflicting record, or restrictive CAA The records and any CAA entry
Works on one network, fails on another Stray AAAA record, or stale cache Remove or test IPv6, then compare resolvers
Redirect loop Both the CDN and the origin force redirects, or protocol is mis-detected Disable one rule, test each layer separately
Padlock with a warning symbol Mixed content Browser console, then fix the addresses in the source
Sitemap lists the wrong domain site option incorrect astro.config, rebuild, redeploy

Limits and what to watch for

  • Rate limits. Authorities limit how many certificates can be requested for a domain in a period. Use their staging environments for experiments.
  • Verification can lapse. If you later remove the DNS record or the web server rule that proved control, renewal may fail. Keep what renewal needs in place.
  • Two TLS legs with a CDN. Visitors connect to the CDN, and the CDN connects to your origin. Both need valid certificates and a mode that checks them.
  • HSTS is sticky. Browsers remember it for the period you set. Break HTTPS during that time and visitors cannot click through.
  • HTTPS protects the connection, not the content. It does not stop a vulnerable dependency or an exposed secret from causing harm.
  • Registration renewal. A valid certificate cannot help if the domain registration expires. Keep reminders for both.

Summary

For an Astro site, DNS and HTTPS come down to a short chain: records that point the name at the host, a certificate that covers the root and www names, a permanent redirect to one canonical https address, and a project whose site setting and content use that same address. Add HSTS carefully once everything works, check each variant of the address with curl, and repeat the checks after any change to DNS, hosting or CDN rules.

If you still need to choose or register the name this setup depends on, the domains page is a good place to start.

Frequently asked questions

Does an Astro site need a certificate of its own?

The site needs a certificate somewhere in the path that serves it. On many managed static hosts the host issues and renews it for you after the domain is verified. On your own server or behind a CDN you arrange the certificate yourself or use the CDN's.

Which DNS records do I need for HTTPS on Astro?

The same ones as for any site: an A record for the root domain, a record for www, and an AAAA record only if the host provides IPv6. A CAA record is optional and limits which authorities may issue certificates.

Where do I set up redirects from http to https?

At the layer that serves the site: the host's dashboard or configuration file on a managed host, the web server configuration on your own server, or the CDN rules if one sits in front. Astro can also define redirects in its configuration for page-to-page moves, but the http to https redirect belongs to the server layer.

Why does the browser report mixed content on my Astro pages?

A page loaded over https is still requesting a script, image, font or stylesheet from an http address. Search the components, content files and public variables for hard-coded http addresses and replace them with https or relative paths.

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

How to Set Up DNS and HTTPS for a Laravel Site

A practical guide to DNS records, certificates, HTTP-to-HTTPS redirects, HSTS and the Laravel settings that keep every link and cookie secure.

10 min read

Domain & DNS Guides

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

A focused guide to the DNS records and HTTPS settings a Ghost site needs: record types, TTL, certificates, redirects and how to troubleshoot warnings.

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