HTTPS on localhost on a Mac
Updated · 2 min read
First, check that you need it. Browsers already treat http:/ as a secure page, so service workers, the clipboard and most secure-only browser features work over plain HTTP. You need a real https:/ address when:
- an OAuth provider or payment SDK accepts only
https:/callback addresses;/ - you test cookies set with
SecureorSameSite=Nonethe way production sends them; - you want development to behave like production, mixed-content warnings included.
With mkcert
mkcert makes a certificate authority on your Mac, asks macOS to trust it, and signs certificates for the names you give it:
brew install mkcert
mkcert -install
mkcert localhost shop.localhostmkcert -install asks for your password once. The last command writes a certificate and its key into the current folder; point your dev server at the two files (each framework has its own https option).
- Each name needs to be listed. Browsers don't accept a certificate for
*.localhost, so a new project means a new certificate. - Firefox keeps its own list of trusted authorities. Install
nss(brew install nss) beforemkcert -installso mkcert can add itself there, or turn onsecurity.enterprise_roots.enabledinabout:config. - Keep the authority's key private.
mkcert -CAROOTshows where it is. Anyone with that file can make certificates this Mac trusts, for any site.
Undo it
mkcert -uninstalltakes the trust back. Delete the folder mkcert -CAROOT prints to remove the key too.
How Portroom handles itPRO
HTTPS for every project, without certificates to manage
Turn on HTTPS in Settings ▸ Ports & URLs. Portroom makes a certificate authority of this Mac’s own, macOS asks for your password once, and every project opens at https://<name>.localhost too, with a certificate made the first time a browser asks for that name. Your servers don’t change: Portroom handles HTTPS in front of them.
The authority can sign localhost names only, so even its key couldn’t pass off another site as the real one. Remove takes the trust back and deletes the certificates.
Part of Pro, $49 once. Portroom starts with 14 days of Pro, so you can try it first.
Something wrong or out of date on this page? Write to support@portroom.dev.