HTTPS on localhost on a Mac: trusted certificates for dev servers
Why a dev server needs HTTPS, how to set it up with mkcert, and how Localfox keeps a stable HTTPS address.
Plain http://localhost:5173 works until it does not. Some browser features and login providers need a secure origin, and the moment you add one, a self-signed certificate shows a warning on every reload. This guide sets up trusted HTTPS for a local dev server on macOS, first by hand and then with Localfox.
When a dev server needs HTTPS
- Cookies with
SecureorSameSite=None. A login flow that works in production can silently fail on plain HTTP. - OAuth and SSO providers that accept only
https://redirect URLs, or that you want to register once with a fixed address. - Service workers, the Clipboard API, camera and microphone access, and other APIs that need a secure context on a name other than plain
localhost. - Two local apps that call each other, where mixed HTTP and HTTPS breaks requests.
Use a .localhost name, not a port
macOS resolves every *.localhost name to your own Mac. wishfox.localhost and api.wishfox.localhost work with no /etc/hosts entry and no DNS server. Vite also allows localhost and *.localhost in its host check by default. A made-up suffix such as .test needs a resolver, and Vite refuses it with "Blocked request. This host is not allowed." Avoid .local. It belongs to Bonjour.
Set it up by hand with mkcert
mkcert creates a local certificate authority, trusts it on your Mac, and issues certificates signed by it.
brew install mkcert
mkcert -install
mkcert wishfox.localhostmkcert -install adds the authority to your keychain. macOS asks for your password. The last command writes wishfox.localhost.pem and wishfox.localhost-key.pem to the current folder. Point Vite at them:
// vite.config.ts
import { readFileSync } from "node:fs";
import { defineConfig } from "vite";
export default defineConfig({
server: {
host: "wishfox.localhost",
https: {
key: readFileSync("wishfox.localhost-key.pem"),
cert: readFileSync("wishfox.localhost.pem"),
},
},
});Open https://wishfox.localhost:5173. The padlock is green. Next.js has a shortcut for the same idea: next dev --experimental-https creates and trusts a certificate for you.
What stays awkward
- The address still has a port. If 5173 is busy, Vite picks 5174, and your OAuth redirect URL and bookmarks break.
- Every project needs its own certificate files and config. Keep the key files out of git.
- Node, Bun and Deno ignore the macOS keychain. A server-side
fetch("https://api.wishfox.localhost")fails until you setNODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"for that process. - To drop the port you need a reverse proxy on port 443, such as Caddy, and binding 443 needs root.
Get a stable HTTPS address with Localfox
Localfox is a free menu bar app that does the proxy part for you. Add a project folder. Localfox detects the framework, the package manager and the dev command, starts the server, finds the port it actually opened, and serves it at https://wishfox.localhost with no port. If the server moves to another port, the address stays the same.
- A bundled Caddy proxy owns ports 80 and 443 through a small helper that you approve once in System Settings.
- Localfox runs its own certificate authority and trusts it in your login keychain once, after you ask. Removing it with
brew uninstall --zapremoves the authority too. - It sets
NODE_EXTRA_CA_CERTSfor every server it starts, so server-side requests to other.localhostapps work. - A port route gives a domain to something Localfox did not start, such as a Docker container.
brew install --cask xergic/tap/localfoxNo Homebrew? Download the app from localfox.kandera.cz/download. Localfox needs macOS 15 or later and an Apple Silicon Mac. It is free.
Check your setup
curl -I https://wishfox.localhostA trusted setup returns a status line with no certificate error. If curl reports a certificate problem, the authority is not trusted yet. Run mkcert -install again, or finish the HTTPS step in Localfox. If something else already holds the port you need, Portfox shows what is using it.