Automatic Https With Caddy - Extremely Easy

Today I had a chance to try Caddy for dev purpose, and you guess what, it was extremely easy and funny. Only two steps and boom, you got a secured website almost instantly.
Here are the steps I followed:

Install Caddy on Ubuntu/Debian

Check their documentation for another OS/installation method.

1sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
2curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
3curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
4sudo apt update
5sudo apt install caddy

Edit Caddyfile and restart the service

1sudo vim /etc/caddy/Caddyfile
1dev-api.your-domain.com
2
3reverse_proxy 127.0.0.1:8000
1sudo systemctl restart caddy
2# or
3sudo caddy reload

That's it, you can now browse https://dev-api.your-domain.com.
In my case, a REST API service was running on port 8000 and I configured Caddy as a reverse proxy.
Configuring Caddy should be easy for other use cases as well, I'm pretty sure.

If you were to configure multiple domains:

1dev-api.domain-one.com {
2  reverse_proxy 127.0.0.1:8000
3}
4
5dev-app.domain-two.com {
6  reverse_proxy 127.0.0.1:3000
7}

Happy coding!

comments powered by Disqus