I’m finally biting the bullet here and updating from Caddy to Caddy 2 and wresting with the new format Caddyfile. After much wailing and gnashing of teeth, I’ve managed to suss out all the difficult stuff like reverse proxying,etc. But I’m being completely stymied by the syntax for adding multiple domains.
Here’s my first domain:
#||||||||||| madra.net ||||||||||||||
#redirect www
www.madra.net {
redir https://madra.net{uri}
}
# the main wan
madra.net
root * /www/madra.net/public
# logging
log {
output file /www/loganna/madra.net.access.log
}
# error handling
handle_errors {
rewrite * /{http.error.status_code}.html
file_server
}
# gzip encoding
encode gzip
# calibre-web
handle_path /calibre* {
reverse_proxy localhost:33336 {
header_up X-Script-Name /calibre
}
}
# run as static file server
file_server
#||||||||||| madra.net ||||||||||||||
That works fine. But if I add a second domain to the file:
#||||||||||| stiobhart.net ||||||||||||||
#redirect www
www.stiobhart.net {
redir https://stiobhart.net{uri}
}
# the main wan
stiobhart.net
root * /www/stiobhart.net/public
# logging
log {
output file /www/loganna/stiobhart.net.access.log
}
# error handling
handle_errors {
rewrite * /{http.error.status_code}.html
file_server
}
# gzip encoding
encode gzip
# isso comments
handle_path /isso* {
reverse_proxy localhost:8080 {
header_up X-Script-Name /isso
}
}
# run as static file server
file_server
#||||||||||| stiobhart.net ||||||||||||||
I get the following error:
ERROR watcher unable to load latest config {"config_file": "Caddyfile", "error": "adapting config using caddyfile: Caddyfile:48: unrecognized directive: www.stiobhart.net"}
“OK”. I thought. “Looks like Caddy thinks the second domain is a directive of the first. Maybe I need to bracket both domains to keep them separate?” So I replaced:
#redirect www
www.madra.net {
redir https://madra.net{uri}
}
# the main wan
madra.net
<snip>
with
#redirect www
www.madra.net {
redir https://madra.net{uri}
}
# the main wan
madra.net {
<snip>
}
and likewise for the second domain. But now I get the following error:
ERROR watcher unable to load latest config {"config_file": "Caddyfile", "error": "adapting config using caddyfile: subject does not qualify for certificate: 'stiobhart.net{'"}
If I add any further domains that error changes to refer to whichever is the last one in the Caddyfile. So how do I handle multiple domains in this new style Caddyfile syntax?