Skip to content

Trusted HTTPS on localhost for development with mkcert

Learn how to set up trusted local HTTPS with mkcert so your browser stops warning you about your development server. You will install a local certificate authority, issue one certificate that covers localhost and its subdomains, and serve it from nginx, Caddy, Vite and docker-compose.

This guide walks you through getting trusted HTTPS working on your own machine with mkcert, a small tool for developers who test locally. If your dev server runs on https://localhost, your browser probably greets you every morning with a full-page security warning you have to click past. The short answer is to run mkcert -install once, which creates a certificate authority (a CA is the thing that signs certificates so browsers accept them) that lives only on your machine. You then issue one certificate from it covering localhost, *.localhost and the loopback addresses. By the end you will have that certificate serving from nginx, Caddy, a Vite dev server and a container, with a padlock instead of a warning and no NODE_TLS_REJECT_UNAUTHORIZED=0 in your shell profile.

What you’ll accomplish

  • Install mkcert and generate a local root CA registered in the system trust store, plus the NSS store that Firefox and Linux Chrome use.
  • Issue one leaf certificate covering several hostnames, a *.localhost wildcard, and 127.0.0.1 / ::1.
  • Serve that certificate from nginx, Caddy, a Node or Vite dev server, and a docker-compose service via a bind mount.
  • Trust the same root CA inside a container image, and understand why copying the CA private key between machines is a bad trade.
  • Know the clean uninstall path, and the boundary where mkcert stops being the right tool.

Prerequisites

  • A workstation you administer. Installing a CA into the system trust store needs an administrator password (sudo on macOS and Linux, a UAC prompt on Windows).
  • A package manager: Homebrew on macOS, Chocolatey or Scoop on Windows, or the mkcert binary from GitHub releases on Linux.
  • On Linux, certutil from libnss3-tools. Install it before running mkcert -install, or Firefox and Chrome will keep warning while curl is perfectly happy.
  • Trust stores differ per OS and per browser, and that difference is the source of most confusion here. macOS has one Keychain that Safari and Chrome both read, but Firefox always uses its own NSS database. Linux has a system bundle for CLI tools plus a separate NSS database per browser profile. Windows has the certificate store that Edge and Chrome read, while Firefox on Windows may need security.enterprise_roots.enabled set to true.
  • Basic familiarity with whichever server you are wiring this into. If you have never generated a certificate by hand, creating a CSR and a self-signed certificate with OpenSSL is useful background for what mkcert is automating.

How it works

mkcert splits the problem into two halves that people usually conflate. The first half is the authority: a root CA key pair generated once, stored in a directory on your machine, and registered in every trust store mkcert can find. The second half is the leaf: an ordinary server certificate, signed by that root, listing the exact names you will type into the address bar.

Diagram of the mkcert trust chain from local root CA through system and NSS trust stores to a validated browser connection

The trust decision happens entirely on the first half. When your browser connects to https://app.localhost, it receives the leaf certificate, walks the signature chain up to the root, and asks the trust store whether it recognises that root. Because mkcert -install put it there, the answer is yes, and the connection is validated with no interstitial. Nothing about the leaf certificate is special — the difference from a self-signed certificate is purely that something above it is trusted.

That also explains the failure modes. A tool that reads a different trust store — Firefox with its own NSS database, Node.js with its compiled-in CA bundle, a container with a bare ca-certificates package — will reject the exact same certificate that Chrome accepts, because it never saw the root. Every mkcert problem worth troubleshooting is a variation on “which trust store is this process reading?”

Step-by-step

1. Install the NSS tools first, then mkcert. Order matters on Linux: mkcert only writes to the NSS store if certutil exists at install time.

# macOS
brew install mkcert
brew install nss   # only needed if you use Firefox

# Debian / Ubuntu
sudo apt install libnss3-tools
# then install the mkcert binary from the GitHub releases page

# Windows (PowerShell, as Administrator)
choco install mkcert

Confirm the binary is on your path:

mkcert -version

You should see a version string such as v1.4.4.

2. Create and install the local root CA. This is the only step that needs elevated rights.

mkcert -install

Expected output on a machine with both stores available:

Created a new local CA 💥
The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox and/or Chrome trust store (requires browser restart)! 🦊

If the second line about Firefox and Chrome is missing, certutil was not found. Install libnss3-tools, then re-run mkcert -install — it is safe to run repeatedly.

3. Find out where the CA lives. You will need this path for containers, for Node, and for the uninstall check.

mkcert -CAROOT

Typical output: /Users/you/Library/Application Support/mkcert on macOS, or /home/you/.local/share/mkcert on Linux. That directory holds two files: rootCA.pem, the public certificate you may distribute freely, and rootCA-key.pem, the private key that can mint a trusted certificate for any hostname on any machine that trusts it. Treat the second file the way you would treat a production signing key.

4. Issue one leaf certificate covering everything you browse to. Pass every name and IP in a single invocation — one certificate with several SANs is far easier to manage than five certificates.

mkcert app.localhost "*.localhost" localhost 127.0.0.1 ::1
Created a new certificate valid for the following names 📜
 - "app.localhost"
 - "*.localhost"
 - "localhost"
 - "127.0.0.1"
 - "::1"

The certificate is at "./app.localhost+4.pem" and the key at "./app.localhost+4-key.pem" ✅

It will expire on 5 November 2028 🗓

Quote the wildcard so your shell does not expand it. Note that a wildcard matches exactly one label: *.localhost covers api.localhost but not v1.api.localhost, so list deeper names explicitly if you use them.

5. Give the files predictable names. Default filenames encode the SAN count, which changes every time you add a name and breaks your server config. Pin them instead.

mkdir -p ./certs
mkcert -cert-file ./certs/local.pem -key-file ./certs/local-key.pem \
  app.localhost "*.localhost" localhost 127.0.0.1 ::1

Add certs/ to .gitignore. The leaf key is less dangerous than the CA key, but there is no reason for it to be in version control.

6. Wire it into nginx.

server {
    listen 443 ssl;
    http2 on;
    server_name app.localhost;

    ssl_certificate     /etc/nginx/certs/local.pem;
    ssl_certificate_key /etc/nginx/certs/local-key.pem;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
    }
}
sudo nginx -t && sudo nginx -s reload

Success looks like syntax is ok followed by test is successful. If you want the reload workflow explained properly, see testing and reloading nginx configuration safely.

7. Wire it into Caddy. Caddy would normally fetch its own certificate; the explicit tls directive tells it to use yours instead and skip ACME entirely.

https://app.localhost {
	tls /etc/caddy/certs/local.pem /etc/caddy/certs/local-key.pem
	reverse_proxy 127.0.0.1:3000
}
caddy validate --config /etc/caddy/Caddyfile

Expected: Valid configuration.

8. Wire it into a Node or Vite dev server.

// vite.config.js
import { defineConfig } from 'vite'
import fs from 'node:fs'

export default defineConfig({
  server: {
    host: 'app.localhost',
    https: {
      key: fs.readFileSync('./certs/local-key.pem'),
      cert: fs.readFileSync('./certs/local.pem'),
    },
  },
})

Node does not read the system trust store, so any code in your app that makes an outbound HTTPS call to another local service will still fail. Point Node at the root CA explicitly:

export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"

9. Wire it into docker-compose. Bind-mount the pair read-only; do not bake leaf certificates into images.

services:
  web:
    image: nginx:1.27
    ports:
      - "443:443"
    volumes:
      - ./certs/local.pem:/etc/nginx/certs/local.pem:ro
      - ./certs/local-key.pem:/etc/nginx/certs/local-key.pem:ro
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
docker compose up -d && docker compose logs web

10. Trust the root CA inside a container image. This is for containers that need to call a locally issued HTTPS endpoint, not serve one. Copy only rootCA.pem — never the key.

FROM node:22-bookworm-slim
COPY rootCA.pem /usr/local/share/ca-certificates/mkcert-root.crt
RUN update-ca-certificates
ENV NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt

Debian requires the .crt extension in that directory or update-ca-certificates silently ignores the file. On Alpine, add RUN apk add --no-cache ca-certificates before the update command.

11. For a team, share the public certificate — not the CA key. The tempting shortcut is to commit rootCA-key.pem so everyone issues from the same authority. Do not. That key lets anyone holding it issue a trusted certificate for any domain, including your bank, valid on every machine that installed it — and once it is in git history it is effectively unrevocable. The safe pattern is that each developer runs mkcert -install to get their own CA, and only rootCA.pem is distributed when a container or CI job needs to validate someone else’s certificate. If you genuinely need one shared authority across a team, that is the job of an internal ACME CA, covered in running an internal ACME CA with step-ca.

Validate it works

Confirm the chain from the command line first — this isolates certificate problems from browser caching.

openssl s_client -connect app.localhost:443 -servername app.localhost \
  -CAfile "$(mkcert -CAROOT)/rootCA.pem" </dev/null 2>/dev/null | grep -E "Verify return code|subject="

You want Verify return code: 0 (ok). Anything else means the chain did not validate against the root.

Check that the certificate actually lists the name you are browsing to:

openssl x509 -in ./certs/local.pem -noout -text | grep -A1 "Subject Alternative Name"
X509v3 Subject Alternative Name:
    DNS:app.localhost, DNS:*.localhost, DNS:localhost, IP Address:127.0.0.1, IP Address:0:0:0:0:0:0:0:1

Then check the system trust path, with no -k and no --cacert:

curl -sS -o /dev/null -w "%{http_code} %{ssl_verify_result}\n" https://app.localhost/

200 0 means curl validated it through the trust store. Finally, restart your browser completely and load https://app.localhost — you should get a padlock, and clicking it should show the certificate issued by mkcert <your-user>@<your-host>.

Troubleshooting

Chrome is fine but Firefox still warns. Almost always certutil was missing when you first ran mkcert -install, so the NSS database was never touched. Install libnss3-tools (Debian/Ubuntu) or nss-tools (Fedora), re-run mkcert -install, and fully quit Firefox — not just the window, the process. Confirm success by looking for the Firefox line in the install output. On Windows, Firefox may ignore the system store entirely; set security.enterprise_roots.enabled to true in about:config.

ERR_CERT_COMMON_NAME_INVALID or a name mismatch. The certificate does not cover the exact hostname you typed. A *.localhost wildcard does not cover bare localhost, and it does not cover two-label subdomains like api.v2.localhost. It also does not cover 127.0.0.1 — IPs must be listed as separate SAN entries. Re-issue with every name in one command rather than adding certificates.

Node, Python, or a container ignores the trust store. These runtimes ship their own CA bundles. Node reads NODE_EXTRA_CA_CERTS, Python’s requests library reads REQUESTS_CA_BUNDLE, and most Go and curl builds read SSL_CERT_FILE. Set the relevant variable to $(mkcert -CAROOT)/rootCA.pem, or install the root into the image as shown in step 10. Reaching for NODE_TLS_REJECT_UNAUTHORIZED=0 disables verification globally for that process and has a habit of surviving into non-dev environments.

The certificate stopped working after a couple of years. mkcert deliberately caps leaf certificate lifetime — since v1.4.2 they are issued for about two years and three months, matching browser policy on maximum certificate validity. Long-lived local certificates are a real hazard, so this is by design. Re-run the same mkcert -cert-file ... -key-file ... command; the root CA is unaffected and no browser restart is needed.

Docker container serves the old certificate after you regenerated it. Bind mounts of individual files capture the inode at container start. Recreate the container rather than restarting it: docker compose up -d --force-recreate web.

You want it gone. mkcert -uninstall removes the root CA from the trust stores it installed into, but leaves $(mkcert -CAROOT) on disk. Delete that directory afterwards if you want a genuinely clean slate, and remember that any leaf certificates you issued become untrusted immediately.

When this is the wrong approach

mkcert is a development tool and its own documentation is blunt about that. Never point it at staging, a shared demo box, or anything reachable from outside your machine: every visitor would need your root CA installed, which means asking people to trust an authority you cannot revoke. Never generate mkcert certificates in CI and ship the artifact anywhere, and never let rootCA-key.pem leave the machine that created it — a leaked local CA key is a working interception capability against every device that trusts it.

For anything with a public hostname, use Let’s Encrypt with Certbot or the automatic HTTPS built into your reverse proxy. For internal services on private hostnames where you need one authority across many machines with real revocation and short-lived automated renewal, run an internal ACME CA such as step-ca instead. The dividing line is simple: mkcert is for one developer’s machine, and everything beyond that needs a CA someone can operate. The official documentation lives at github.com/FiloSottile/mkcert.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.