💻
blog.cat.ssl

SSL for local development: trusted HTTPS with mkcert

24.11.2026
← All articles

During development http://localhost is usually enough, but some features only work in a secure context: Service Workers, geolocation, camera and microphone access, cookies with the Secure flag or a payment provider's test widget. Mirroring a production HTTPS setup locally also catches bugs earlier. A self-signed certificate works, yet the browser warns you every time. mkcert solves this much more cleanly.

How mkcert works

mkcert creates a small private certificate authority on your machine and adds its root certificate to the operating system and browser trust stores. Any certificate it issues is then trusted on your computer, so the padlock appears with no warning. That trust exists only on your machine, which is exactly why mkcert is meant for development and testing, never for public sites.

Installation

mkcert runs on Windows, macOS and Linux. On Linux you need libnss3-tools for the Firefox and Chrome stores; on macOS install nss if you use Firefox. If your distribution does not package mkcert, download a release from the project's official page.

# Windows (Chocolatey or Scoop)
choco install mkcert
scoop bucket add extras
scoop install mkcert

# macOS
brew install mkcert
brew install nss        # for Firefox

# Ubuntu / Debian
sudo apt install libnss3-tools mkcert

Install the local CA

Run this once per computer. The second command shows where the CA files live. Never share rootCA-key.pem or commit it: anyone holding it can mint certificates your machine will trust for any site, including your bank.

mkcert -install
mkcert -CAROOT

Issue a certificate for a project

Say you are building a booking site for a Tashkent training centre and want to use example.test locally. One command covers the name, its subdomains, localhost and loopback IPs. The .test zone is reserved for testing and will never be sold as a real domain; avoid .local, which can clash with mDNS.

mkcert example.test "*.example.test" localhost 127.0.0.1 ::1

# Output:
#  ./example.test+4.pem      (certificate)
#  ./example.test+4-key.pem  (private key)

Map the names to 127.0.0.1 in your hosts file (on Windows, edit it as administrator):

# Linux / macOS: /etc/hosts
# Windows: C:\Windows\System32\drivers\etc\hosts
127.0.0.1   example.test
127.0.0.1   api.example.test

Node.js, Vite and Nginx

With the key and certificate ready, plug them into any server. A minimal Node.js server using the built-in https module:

const https = require('https');
const fs = require('fs');

const options = {
  key: fs.readFileSync('./example.test+4-key.pem'),
  cert: fs.readFileSync('./example.test+4.pem'),
};

https.createServer(options, (req, res) => {
  res.end('HTTPS works');
}).listen(8443);

For Vite, point server.https at the same files:

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

export default defineConfig({
  server: {
    host: 'example.test',
    https: {
      key: fs.readFileSync('./example.test+4-key.pem'),
      cert: fs.readFileSync('./example.test+4.pem'),
    },
  },
});

For a local Nginx or Docker setup, mount the files and write a normal SSL block. Keep the files out of the repository via .gitignore; each developer generates their own.

server {
    listen 443 ssl;
    server_name example.test;
    ssl_certificate     /etc/nginx/certs/example.test+4.pem;
    ssl_certificate_key /etc/nginx/certs/example.test+4-key.pem;
    root /var/www/example;
}

Phones and other gotchas

To test on a phone, include your computer's LAN IP such as 192.168.1.20 in the certificate and install rootCA.pem on the device as trusted; on iPhone you must also enable full trust for it in settings. Some runtimes ignore the system store: set NODE_EXTRA_CA_CERTS to the rootCA.pem path for outgoing Node.js requests. Run mkcert -uninstall when you hand the computer to someone else.

Going to production

Never deploy an mkcert certificate on a public server; visitors' browsers will reject it. A live site needs a certificate from a public CA such as Let's Encrypt. On sayt.uz hosting, for example, a free Let's Encrypt certificate is enabled in the panel and renews automatically. mkcert locally, a public certificate in production.

Related articles

🔒 How to Fix Mixed Content in WordPress: A Step-by-Step Guide 🔍 Free Tools to Check Your SSL Certificate: From Browser to Terminal 🔄 The End of OCSP and the Return to CRLs: What Site Owners Should Know 🔐 The ACME Protocol Explained: How SSL Certificates Are Issued Automatically
🌐 Language
🇺🇿 O⁠'zbek 🇺🇿 Özbek (yangi) 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓