Privacy and Security

HTTPS on Localhost: Making and Trusting a Self-Signed Certificate

When you need HTTPS for local development or home-lab devices, how to build a self-signed certificate that browsers accept, and how to trust it safely.

Saizul Amin
Saizul Amin5 Nov 2026 · 4 min read
HTTPS on Localhost: Making and Trusting a Self-Signed Certificate

Sooner or later every web developer needs HTTPS on a machine that is not a public server. Service workers, secure cookies, the camera and microphone, clipboard access, and sign-in providers all expect a secure origin. Home-lab devices such as a NAS, a router admin page or a Raspberry Pi dashboard also ask for HTTPS. Public certificate authorities will not help with names like localhost or 192.168.1.50, so the answer is a certificate you sign yourself.

What "self-signed" means

A normal certificate is signed by a certificate authority that browsers already trust. A self-signed certificate is signed with its own key. It is just as strong cryptographically, but nobody trusts it until they decide to. That is exactly what you want for development: the only device that needs to trust it is yours.

The detail that breaks most certificates

Old tutorials put the host name in the Common Name (CN) and stop there. Since 2017 browsers ignore the Common Name completely and look only at the Subject Alternative Name (SAN) extension. A certificate for CN=localhost without a SAN entry produces a name mismatch error even after you trust it.

So list every name and address you will type in the browser:

  • localhost, plus 127.0.0.1 and ::1 for IP access
  • your test domain, for example myapp.test, and a wildcard such as *.myapp.test for sub-domains
  • the LAN IP of a device, such as 192.168.1.40, if you open it from a phone

Choosing a key and a lifetime

ECDSA P-256 keys are small and fast, and every current browser, Node, Python, Go, nginx and Apache supports them. RSA 2048 is the conservative choice for older Java versions, printers and embedded devices.

Keep server certificates to 397 days or less. Apple's systems reject TLS certificates valid for more than 825 days, even ones you have trusted manually, and 397 days matches what public CAs issue. A local root CA (see below) can live much longer.

Making one in the browser

The Self-Signed Certificate Generator builds the certificate with Web Crypto, so the private key is created on your own device.

  1. Start from a preset: localhost, a dev domain with a wildcard, a device IP, a local root CA, or a client certificate for mutual TLS.
  2. Fill in the names: the Common Name and the SAN list, one entry per line. The checks underneath warn about missing SANs and other common mistakes.
  3. Choose the key type, usage and validity.
  4. Type a PFX password if you need a .pfx for Windows, IIS, .NET or Java. You can also encrypt the PEM key with it.
  5. Generate, then download the ZIP: certificate as PEM and DER, the private key, the PFX and a readme with the fingerprint.

Trusting it on your device

Trusting a certificate means telling your system "accept this one". Do it only for certificates you made yourself.

  • macOS: double-click the .crt and set it to Always Trust in Keychain Access, or run security add-trusted-cert from the Terminal.
  • Windows: open the .crt, choose Install Certificate, Local Machine, and place it in Trusted Root Certification Authorities.
  • Linux: copy the PEM into /usr/local/share/ca-certificates (Debian, Ubuntu) and run update-ca-certificates.
  • Firefox keeps its own list on some systems; import it under Settings, Certificates, Authorities.
  • iPhone and iPad: install the profile, then enable full trust under Settings, General, About, Certificate Trust Settings.

Then point your server at the files. For nginx, ssl_certificate and ssl_certificate_key take the two PEM paths. Node's https.createServer and Vite's server.https option take the same pair.

One root, many certificates

If you run several local sites, trusting each certificate separately becomes tedious. The alternative is a local root CA: a certificate with the CA flag that you trust once on every device. You then sign each site's certificate with it, using OpenSSL or a tool such as mkcert, and every device accepts them automatically. Guard the root's private key carefully, because anything signed with it is trusted by your machines.

What not to do

Do not use a self-signed certificate on a public website; visitors will see a full-page warning, and they should. Use a free certificate from Let's Encrypt or your host instead. Do not share your private key, commit it to git, or install someone else's root CA on your devices. And never click through certificate warnings on sites you did not set up yourself: on the public internet, that warning is the browser protecting you.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages