- Published on
Instant HTTPS your localhost with Caddy
- Authors
- Name
- Ashik Nesin
- @AshikNesin
Here's an interesting thing that I've learned about running localhost on HTTPS protocol almost instantly.
Install the Caddy Server
You can install it using Brew by running the following command
brew install caddy
And once the installation is done. You can run localhost on HTTPS by reverse proxying it.
You can do it in two ways.
Running Caddy Reverse Proxy with CLI
Start your local dev server. In my case, it's running in port 3001. Then we can reverse proxy it with the following command
caddy reverse-proxy --from example.localhost --to localhost:3001
If you're doing it for the first time, then it'll ask for a password for your machine to set up Caddy's CA. Make sure to enter it to setup properly.
Running Caddy Reverse Proxy with Caddyfile
Create a new Caddyfile
and configure your reverse proxy
example.localhost {
reverse_proxy localhost:3001
}
And then run the following command to start the reverse proxy
caddy run
If you want to run it in the background (daemon mode), run the following command instead
caddy start
Credit
- Learned this tip from Wes Bos
Happy HTTPS localhosts!