HTTPS on localhost with Caddy

Jun 24, 2022

How to run HTTPS on loclahost with Caddy v2 server.

Sometimes you may need HTTPS on your localhost. For example when you want to try some otherwise restricted API in JavaScript. There is easy way how to do that with Caddy server.

This config file will create reverse proxy from https://localhost:2000 to some service which runs on

Caddy v2 config file

tls internal

start server with config

caddy run -config Caddyfile

You can do it even without config file with these commands

run these commands

caddy trust
caddy reverse-proxy --to --from localhost:2000

Both of these commands will add self-signed certificate to your truststore and you will have to confirm warning in your browser complaining about it.