Locahl
mkcertViteNext.jsHTTPSlocal development

mkcert + Vite & Next.js Local HTTPS (2026)

Configure mkcert with Vite and Next.js for trusted local HTTPS. Full vite.config.js, next dev --experimental-https, .test domains + hosts file setup.

L

Locahl Team

·2 min read

Run mkcert once, then wire the certificates into Vite or Next.js for trusted https:// local dev.

One-time mkcert setup

BASH
brew install mkcert
mkcert -install
mkdir -p certs
mkcert -cert-file certs/local-cert.pem -key-file certs/local-key.pem \
  localhost 127.0.0.1 ::1 myproject.test "*.myproject.test"

Add to hosts (see edit hosts on Mac or Windows 10 & 11):

TEXT
127.0.0.1 myproject.test
127.0.0.1 api.myproject.test

Full mkcert walkthrough: mkcert SSL local on Mac.

---

Vite + mkcert (React, Vue, Svelte)

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

const certDir = path.resolve(__dirname, 'certs');

export default defineConfig({
  server: {
    host: 'myproject.test',
    port: 5173,
    https: {
      key: fs.readFileSync(path.join(certDir, 'local-key.pem')),
      cert: fs.readFileSync(path.join(certDir, 'local-cert.pem')),
    },
  },
});

Open https://myproject.test:5173 — green padlock, Service Workers enabled.

Vite env variables

BASH
# .env.local
VITE_API_URL=https://api.myproject.test:3001

Run a second Vite/API server on api.myproject.test with the same cert (wildcard *.myproject.test covers it).

---

Next.js + mkcert

BASH
next dev --experimental-https \
  --experimental-https-key ./certs/local-key.pem \
  --experimental-https-cert ./certs/local-cert.pem

Add to package.json:

JSON
{
  "scripts": {
    "dev": "next dev --experimental-https --experimental-https-key ./certs/local-key.pem --experimental-https-cert ./certs/local-cert.pem"
  }
}

Option B: custom .test hostname

mkcert must include the exact hostname. Regenerate if needed:

BASH
mkcert myproject.test localhost 127.0.0.1

Add to /etc/hosts or Windows hosts, then open https://myproject.test:3000.

---

Monorepo: Vite frontend + Next.js API

ServiceURLConfig
Next.js APIhttps://api.myproject.test:3000next dev --experimental-https ...
Vite SPAhttps://myproject.test:5173vite.config.js https block

Use one mkcert command with both names:

BASH
mkcert myproject.test api.myproject.test "*.myproject.test" localhost

After hosts changes, flush DNS on Mac or ipconfig /flushdns on Windows.

---

Troubleshooting

ErrorFix
NET::ERR_CERT_AUTHORITY_INVALIDmkcert -install, restart browser → [[mkcert-net-err-cert-authority-invalid-mac
Certificate hostname mismatchRegenerate mkcert including exact URL hostname
Vite HMR WebSocket failsSet server.hmr: { host: 'myproject.test' } in vite.config.js
Next.js only serves localhostPass hostname via --hostname myproject.test if needed

---

.gitignore

GITIGNORE
certs/
*.pem

Commit a scripts/setup-certs.sh instead of the keys.

Conclusion

mkcert + hosts + Vite/Next.js gives production-like HTTPS locally. Generate certs once, map .test domains in hosts, point each dev server at the PEM files, and flush DNS after hosts edits.

Also readComplete mkcert SSL local guide
Share this article
Available on Windows, macOS & Linux

Ready to simplify your workflow?

Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.

  • Intuitive visual interface
  • Automatic DNS flush
  • Multi-environment management
  • Automatic backups
  • JSON Import/Export
Buy Locahl, €4.99One-time payment, no subscription

Frequently Asked Questions

Does Next.js support mkcert certificates natively?

Yes — Next.js 13+ supports next dev --experimental-https with --experimental-https-key and --experimental-https-cert pointing to mkcert PEM files.

Can Vite use a custom .test domain with mkcert?

Yes. Generate mkcert for myproject.test, add 127.0.0.1 myproject.test to hosts, set server.host in vite.config.js.

Where is the full mkcert install guide?

See the complete [[https-local-ssl-certificate-mac|mkcert SSL local setup on Mac]] — this article focuses on Vite and Next.js wiring.

Related Articles

3 min read
hosts fileWindows 1124H2

Edit Hosts File on Windows 11 24H2 (2026)

Windows 11 24H2 hosts file guide: Smart App Control, Controlled Folder Access, Notepad admin, PowerShell, ipconfig /flushdns and Clear-DnsClientCache.

L

Locahl Team

2 min read
cheat sheetDNShosts file

DNS & Hosts File Cheat Sheet (Mac, Windows, Linux)

Printable cheat sheet: flush DNS commands, hosts file paths, mkcert setup, and browser cache clears for macOS, Windows 11, and Linux (2026).

L

Locahl Team

Developer tools team

4 min read
hosts fileadmin rightspermissions

Can You Edit the Hosts File Without Admin Rights?

Can you edit the hosts file without administrator rights? The honest answer plus real alternatives on Windows, Mac and Linux when you cannot elevate (proxy, Docker, local DNS, SSH).

L

Locahl Team

Developer tools team

4 min read
localhostsubdomainslocal development

How to Use Subdomains on localhost for Local Development

Use subdomains on localhost: the free *.localhost trick browsers resolve automatically, fixed subdomains via the hosts file, and wildcard subdomains with dnsmasq on Mac and Linux.

L

Locahl Team

Developer tools team