While Setting up Caddy for Public sites I found that my http://
links were still working. I was under the impression that Caddy will do the automatic redirects. I was using the JSON config, and not Caddyfile
so it was a bit difficult to discover the reason.
Now, here is the weird thing that I discovered. In my JSON config file for caddy, my listen directive was set to
"listen": [":80", ":443"]
and you would think:
Of course Caddy needs to listen on port 80 for it to be able to redirect to port 443.
And you won’t be alone. The thing is though - if you do that, Caddy thinks “you don’t want my automatic HTTPS redirects and want to specify custom rules for each site individually”. Instead you have to ask to listen to port 443 only. And if caddy is able to bind to port 80, it will automatically start listening on port 80 and start redirecting. So changing that line to
"listen": [":443"]
did the trick!
Honestly Caddy devs, this is pretty bizarre as a behavior!