Addendum: custom error pages in Caddy
posted Aug 21, 2025 by huskee
Quick and dirty post, basically an addendum to Easy custom error pages on nginx.
Here's how to do it in Caddy:
Caddy config
(errors) {
map {err.status_code} {comment} {
400 "That wasn't so nice of you"
401 "User not in sudoers file, incident will be reported"
402 "This is going to impact your credit score"
403 "You're really not supposed to be here, but I can't do much"
404 "Even looked under the fridge for it"
405 "No PUT/POST/PATCH/DELETE, 400€ fine"
[rest of me being unfunny goes here]
}
handle_errors 418 {
root /srv/huskee.gay
rewrite * /418.html
file_server
}
handle_errors {
root /srv/huskee.gay
rewrite * /error.html
templates
file_server
}
}
You can have multiple handle_errors
directives if you want to treat certain status codes differently.
This is a snippet, so you just have to import it into each site you'd like to get custom error pages:
huskee.gay {
import errors
}
Error page
Instead of using SSI, we use Caddy's templating abilities.
error.html
(our single error page) should contain something like this:
<h1>{{ph "http.error.status_code"}} {{ph "http.error.status_text"}}</h1>
<p>{{ph "comment"}}</p>
Caddy will replace the above placeholders with the status code, appropriate description and the stupid comment that we mapped to the status code.