How to Use HTTPS on Localhost During Development
Check when loopback HTTP is enough, then create and verify a trusted HTTPS certificate for a localhost-only development server.
- https
- localhost
- tls
- guide
Use http://localhost when it satisfies your local test. Browsers can treat loopback HTTP as a potentially trustworthy origin. Use a trusted local HTTPS server when you need to test an actual TLS connection, a callback that specifically requires an HTTPS URL, or behavior tied to the HTTPS origin.
Check which condition your feature requires
Open your local app as a top-level page and evaluate window.isSecureContext in the browser console. A value of true means the page passes the browser's secure-context check. It does not show that traffic used TLS. The Secure Contexts specification treats loopback IP addresses as potentially trustworthy and sets conditions for treating localhost names the same way.
Suppose a webcam feature already works at http://localhost:3000 but your test harness compares an HTTPS callback URL. Keep the webcam test on its existing origin. Configure HTTPS for the second test and register the exact callback the harness uses, including hostname and port. The browser treats http://localhost:3000 and https://localhost:3000 as separate origins.
Configure a certificate on a development machine
A public certificate authority cannot issue a normal public certificate for the bare name localhost. Let's Encrypt explains why. For a private development setup, use a local issuer you control. For example, on your own development machine, mkcert can create a local certificate authority and a leaf certificate.
- Run
mkcert -installin the development environment that needs the trust change. Verify that the browser or client you use trusts the local issuer. Some clients use separate trust stores. - Run
mkcert -cert-file localhost.pem -key-file localhost-key.pem localhost 127.0.0.1 ::1to generate files covering those exact names and addresses. - Configure the development server's TLS certificate and key files. Keep the listener on loopback. Open
https://localhost:3000if that is the port the server uses. - In the browser's certificate viewer, verify that the certificate is trusted and its subject alternative names include
localhost. If you browse by IP, check the matching IP entry. Trust in the issuer alone cannot fix a name mismatch.
Keep the local CA private key and server key out of source control and shared images. Use distinct trust and keys for production. When a temporary development environment no longer needs the CA, use mkcert -uninstall to remove its trust from the supported local stores, and remove any trust you added separately.
