Caddy is fantastic little production ready server that we can use instead of Apache or Nginx reverse proxy in front of multiple phoenix applications in one box.
The best thing is that we get https without needing to do anything on phoenix side. Caddy automatically provisions a certificate from Let’s encrypt.
All we need to do is just write one line of code.
Some important commands
sudo caddy start
sudo caddy stop
sudo caddy reload
Concept
We need to have a file Caddyfile (no extension) in the directory from where we would start the caddy server.
Say we have Caddyfile in the home directory - /home/sher
This is the content of the Caddyfile -
use.example.app {
reverse_proxy * http://localhost:6001
}
test.example.app {
reverse_proxy * http://localhost:8066
}
example.app {
reverse_proxy * http://localhost:8000
}
another-site.com {
reverse_proxy * http://localhost:4002
}
So we just need to write one line for each domain and our job is done.
Please note
test.example.app {
reverse_proxy * http://localhost:8066
}
Here the phoenix app is still running in localhost but the final url would be https://test.example.app. This happens by magic. So you don’t need to do anything and https should automatically work.
This automatically gives you HTTP/2 which is faster than HTTP/1.1.
My Use case
I run a software development agency and we have several projects running in one box, so Caddy really helps there.
More advanced stuff is also possible. Check out the docs.
I found Caddy really interesting and thought that I should share it with the community.
P.S: I am not associated with Caddy in any way