Caddy Event Hooks

certificate deploy hooks in the caddy webserver

A little follow-up to switching from nginx to caddy.

For prosody, an xmpp server, i needed certificates that i got with certbot and a deploy hook before. Now that i deleted certbot, i needed a way to get and deploy certificates with caddy.

Its not documented very well, but totally possible to do that. In their github issues i found a request for event hooks, and linked there is the implementation with a small example for what the event hook definition should look like.

In the Caddyfile general block (so, at the very top), add the “events” app, and specify the “certificate_obtained” hook:

	events {
		on certificate_obtained exec /bin/foobar --domain {}

In my case i needed to copy the certificate out and change the access rights - so i just wrote a little script, which is executed by this hook. If you use caddy on a debian-like system via their repositories and the systemd service, the files you are looking for are in


in files called <domain>.key for the secret key and <domain>.crt for the certificate.

Last modified 2022.10.29