Guides · Architecture

HTTPS and HSTS basics: certificates, redirects and mixed content.

Set up HTTPS correctly: certificate types, redirecting HTTP, fixing mixed content, what HSTS does, preload risks and how to check it.

Key takeaways

  • HTTPS encrypts traffic between visitor and server and shows that the site is the one it claims to be.
  • Redirect all HTTP URLs to HTTPS with a 301, and make sure assets also load over HTTPS.
  • HSTS tells browsers to use HTTPS only. Enable it carefully, because mistakes are sticky.
  • HTTPS is a small ranking signal and a basic trust requirement.

What HTTPS does

It uses TLS to encrypt data and to confirm the server's identity with a certificate. Without it, anyone on the network path can read or change what is sent, including form entries and cookies. Browsers also mark HTTP sites as "not secure".

Getting a certificate

Free certificates from Let's Encrypt are enough for most websites, and many panels, including aaPanel, can request and renew them for you. Paid certificates exist, mainly for organisation validation or support needs, and give the same encryption.

Steps in a typical panel:

  1. Point your domain's DNS to the server.
  2. Request a certificate for the domain and the www version if you use it.
  3. Enable automatic renewal and check it works.

Redirect HTTP to HTTPS

In Nginx:

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://example.com$request_uri;
}

Choose one canonical host, either with or without www, and redirect the others to it. Use a 301, so search engines transfer signals.

Fix mixed content

A secure page that loads images, scripts or styles over http:// triggers warnings or blocked content. Search your code for http:// references and change them to https:// or to root-relative paths such as /css/style.css. Browser developer tools list mixed content in the console.

HSTS

The Strict-Transport-Security header tells the browser "only use HTTPS for this site for the next N seconds".

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Start with a short max-age such as a day or a week, check that everything works, then increase it. If a subdomain does not support HTTPS and you used includeSubDomains, that subdomain becomes unreachable for visitors who have cached the policy.

HSTS preload

A preload list ships with browsers, so even a first visit uses HTTPS. It is difficult to leave, so submit only when you are sure every subdomain will always support HTTPS.

Other useful security headers

  • Content-Security-Policy limits where scripts and styles may load from. See a CSP hash for a theme toggle.
  • X-Content-Type-Options: nosniff.
  • Referrer-Policy to limit what is sent to other sites.
  • Permissions-Policy to disable features you do not use.

Check your setup

  • Open the site in a browser and inspect the padlock details.
  • Run curl -I http://example.com and confirm a 301 to HTTPS.
  • Use an online TLS test such as SSL Labs.
  • Check the certificate's expiry and renewal logs.

Common mistakes

  • Redirect loops, often caused by a proxy or CDN terminating TLS while the server redirects again.
  • Forgetting the www or a subdomain on the certificate.
  • Not renewing in time.
  • Hard-coded http:// URLs in the database or templates.

Frequently asked questions

Is HTTPS needed for SEO?

It is a lightweight signal, but the bigger reason is trust and security.

Does HTTPS slow the site?

Modern TLS and HTTP/2 add very little. Often the site becomes faster, because HTTP/2 needs HTTPS in browsers.

Can I use HSTS on localhost?

No need. Use HSTS in production only.

See how I handle security headers on this site.

Read the post