Skip to content

DNS and HTTPS are usually set up on the same afternoon, and for good reason: the certificate that makes the padlock appear can only be issued once the domain name points at your server. If DNS is wrong, certificate issuance fails. If the certificate is fine but the application still generates http links, browsers show warnings and cookies misbehave. For a Laravel site the work therefore spans three layers: the DNS records at the domain, the certificate and redirects at the web server, and a handful of settings inside the application.

This guide covers all three in order and finishes with a checklist you can use to confirm that each layer is correct. It focuses on a Laravel site on a server you control or a hosting plan that lets you edit the web server configuration. The same ideas appear for other stacks in the guides for React, Astro and Next.js. If you still need a name to work with, the domains page shows how registration works.

Why DNS and HTTPS belong together

HTTPS is HTTP carried inside an encrypted TLS connection, as Cloudflare's overview of HTTPS explains. Two things happen when a browser opens an https address. It checks that the certificate presented by the server is valid for the domain being visited, and it uses keys agreed during the handshake to encrypt everything that follows. The first check is the reason DNS matters: a certificate is issued for a name, and the authority that issues it wants proof that the person asking controls that name and the server behind it.

Automated authorities use the ACME protocol described in RFC 8555. In the most common validation, the authority asks the server to publish a small token at a well-known path on port 80 and then fetches it using the domain name. For that fetch to succeed, DNS has to resolve the name to your server, and the web server has to be reachable and answer for that name. A second validation method places a token in a DNS TXT record, which is useful for wildcard certificates or servers that cannot open port 80, at the cost of needing access to edit DNS during issuance.

So the dependency is simple. DNS first, then the web server answering on port 80, then the certificate, then the redirect, then the application settings. Working in that order prevents most of the confusing half-working states.

The DNS records a Laravel site needs

Records are defined in the DNS specifications such as RFC 1035. A typical Laravel site needs only a few.

Record Purpose Notes
A Maps a name to an IPv4 address Needed for the root domain; also common for www
AAAA Maps a name to an IPv6 address Add only if the server really serves the site on that address
CNAME Makes one name an alias of another Often used for www pointing to the root; not allowed alongside other records at the same name
CAA Lists which certificate authorities may issue for the domain Optional; if you add one, include the authority you plan to use
TXT Arbitrary text Used for domain validation challenges and for email authentication

Set the TTL to a moderate value while you work, because short values mean mistakes are corrected quickly. Check the answer from outside your own network with dig or an online lookup tool, and verify that both the root and the www names return the address you expect. If an AAAA record exists, test the site over IPv6 as well, because visitors on IPv6 networks will use it first.

Remember that mail records live in the same zone. If you also use mail on the domain, keep its records untouched while you edit web records, and read the business email page if you need the mail side explained.

Choosing and issuing a certificate

There are two practical routes. The first is an automated certificate from an ACME authority, issued by a client program running on your server or built into your hosting panel. It suits most Laravel sites: the client proves control of the domain, receives a certificate that is valid for a short period, and renews it automatically before it expires. The second is a certificate bought from a commercial authority, which you install manually and renew on a schedule. Reasons to choose it include a validation level that includes organisation details, support from the vendor, or a warranty. The SSL page lists what a provider offers, and the standards for what authorities must verify are maintained by the CA/Browser Forum.

Whichever route you pick, decide which names the certificate must cover. List the root domain and the www name at least. If you use subdomains such as app or staging, either add each one or use a wildcard certificate, which covers one level of subdomains and usually requires the DNS validation method.

With an ACME client such as Certbot or acme.sh on an Nginx server, the typical flow is as follows.

  1. Confirm that the domain resolves to the server and that port 80 is open in the server firewall and any cloud firewall.
  2. Make sure an Nginx server block already answers for the domain name and serves the Laravel public folder.
  3. Run the client for the Nginx plugin (or webroot mode, pointing at the public folder), list every name, and accept the prompts.
  4. Let the client edit or generate the HTTPS server block, or edit it yourself to include the certificate and key paths.
  5. Reload Nginx and visit the https address.

Keep the private key private. It should be readable only by the web server's service and never be placed in the public folder, a repository or a shared drive.

Install, renew and automate

A certificate that is installed once and forgotten will eventually expire and take the site down with a browser warning. Automation removes that risk, so make sure it is working rather than assuming.

  • Check the renewal job. ACME clients usually install a timer or scheduled task. List it and read its log. Many clients also offer a dry run option that simulates renewal without issuing anything; run it after any server change.
  • Make sure renewal can still validate. If you later add a firewall rule, a redirect that catches every path, or an application route that intercepts the validation path, renewal can fail silently. The validation path must remain reachable over plain HTTP.
  • Reload the web server after renewal. The new certificate files are only used after the web server reloads. Most clients have a post-renewal hook for this.
  • Set a reminder anyway. Put the certificate expiry date in a calendar, or use a monitoring service that alerts when a certificate has few days left.

For manually purchased certificates, install the full chain that the authority provides, not only the leaf certificate, because some clients cannot build the chain on their own. The structure of these certificates follows the profile in RFC 5280, but day to day you only need to ensure that the intermediate certificates are included in the file your web server loads.

Redirects, HSTS and a single canonical address

Once HTTPS works, send everyone to it. Add a server block on port 80 that returns a permanent redirect to the https version of the same host and path. Then decide the canonical host (root or www) and redirect the other one, from both http and https, to it. The end state is one address that serves content, and three others that forward to it with one hop.

After redirects are stable, consider HSTS, the Strict-Transport-Security response header. It tells a browser to use only HTTPS for your domain for the number of seconds you specify. The benefit is that the browser no longer even tries plain HTTP for repeat visits. The risk is that if you later break HTTPS, visitors cannot click through the warning, since the browser has been told not to allow downgrades. A careful rollout looks like this:

  1. Confirm HTTPS works on the root domain and every subdomain that will inherit the policy.
  2. Start with a short max-age, for example a few minutes to a day, and check the site.
  3. Extend the period gradually once you are confident.
  4. Add the includeSubDomains directive only if every subdomain truly supports HTTPS.

Do not add the preload directive without reading the requirements of the preload list first, since removal from browsers takes a long time.

Laravel settings that keep HTTPS consistent

The server may serve https perfectly while the application still behaves as if it were on http. Check these items.

  • APP_URL in the .env file should begin with https and match the canonical host. Clear the configuration cache afterwards with php artisan config:clear.
  • Trusted proxies. If TLS ends at a load balancer, CDN or reverse proxy, Laravel receives plain HTTP from it. Configure the framework to trust that proxy and to read the forwarded protocol and host headers. Without this, helper functions such as url and asset can produce http links and redirects can loop.
  • Secure cookies. Set the session cookie to be sent only over HTTPS (the secure option in the session configuration, or SESSION_SECURE_COOKIE in the environment file). Keep the HTTP-only flag and an appropriate same-site setting as well.
  • Forcing the scheme. In some deployments, applications call the URL facade's forceScheme method in a service provider, limited to production, to guarantee that generated links use https. This is a fallback; correct proxy configuration is the cleaner fix.
  • Mixed content. Search templates and stored content for hard-coded http addresses for scripts, images and stylesheets. Browsers block or warn about insecure resources on secure pages. Use relative paths or the asset helper.
  • Third-party callbacks. Webhooks, OAuth redirect addresses and payment return URLs are often registered with the old http or localhost address. Update them to the https address.

Verifying the whole setup

Finish with a short checklist, working from the outside in.

Check How Expected result
Names resolve dig or an online lookup for root and www Both return the intended address
Certificate matches Click the padlock, or run openssl s_client against the domain Names include root and www; dates are valid
HTTP redirects Request the http address with curl and read the headers A single permanent redirect to the canonical https address
Other host redirects Request the non-canonical host Redirect to the canonical address
Links are secure View page source and the browser console No http resources, no mixed content warnings
Cookies are secure Browser developer tools, storage section Session cookie marked secure and HTTP-only
Renewal works Dry run of the ACME client Reports success

Run the checks again after any later change to DNS, the server or the proxy, since each of those can undo an earlier step.

Limits and what to watch for

  • Rate limits and caching. Authorities limit how many certificates can be requested for one domain in a period. Use their staging environments while testing so that experiments do not use up the allowance.
  • IPv6 surprises. A stray AAAA record is one of the most common reasons a site works for you but fails for others. Remove it unless you have tested IPv6.
  • CDN and proxy layers. If a CDN sits in front of your server, there are two TLS connections: visitor to CDN and CDN to your server. Configure both, and use a mode that verifies your server's certificate rather than skipping verification.
  • Do not edit during propagation. If a record looks wrong right after a change, wait for the TTL before concluding it failed.
  • HTTPS is not a full security plan. It protects data in transit. It does not fix weak passwords, outdated dependencies or an exposed .env file.
  • Expiry of the domain itself. A valid certificate is useless if the domain registration lapses. Keep renewal reminders for both.

Summary

For a Laravel site, DNS and HTTPS follow one chain: records point the name at the server, the server answers for that name on port 80 so a certificate can be issued, a redirect and optional HSTS make HTTPS the only path, and Laravel is configured so that its own links and cookies agree. Automate renewal, test every address variant, and recheck after changes. Go carefully with HSTS and with anything that makes a mistake sticky in browsers.

If you are still choosing or registering the name that this setup will rely on, the domains page is a good place to start.

Frequently asked questions

Which DNS records does a Laravel site need for HTTPS?

An A record for the server's IPv4 address, an AAAA record only if the server answers on IPv6, and a record for www. Some certificate authorities also allow an optional CAA record that lists which authority may issue certificates for the domain.

Why does the certificate request fail even though the site loads?

The usual causes are DNS that has not finished updating, a firewall that blocks port 80 or 443, a web server that does not answer for the exact domain name being validated, or an AAAA record that points to a machine that does not serve the site.

Do I still need a redirect if I already have a certificate?

Yes. A certificate only enables HTTPS. Visitors who type the plain http address are not moved to HTTPS unless the server sends a redirect.

What is HSTS and should I turn it on?

HSTS is a response header that tells browsers to use HTTPS only for your domain for a period of time. Turn it on only after HTTPS works on every address you use, and start with a short period, because a mistake is hard to undo while browsers remember the rule.

Why does Laravel generate http links behind a proxy?

When a proxy or load balancer ends the HTTPS connection, Laravel only sees plain HTTP from the proxy. Configure trusted proxies so Laravel reads the forwarded protocol header and builds https links.

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 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

How to Set Up DNS and HTTPS for an Astro Site

A practical guide to DNS records, certificates, redirects and HSTS for an Astro site, with the project settings and checks that keep pages and links secure.

10 min read

Domain & DNS Guides

How to Set Up DNS and HTTPS for a Next.js Site

A clear guide to the DNS records, certificates, redirects and checks that put a Next.js site safely on its own domain over HTTPS.

10 min read