Hi!
I stumbled on a surprising behavior of the handle_errors
directive. I was not able to find anything in the documentation, the issues or the forum. I would be grateful if someone has some insight on what is happening.
1. Caddy version (caddy version
):
v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=
2. How I run Caddy:
a. System environment:
I am on Debian Buster.
b. Command:
caddy run
d. My complete Caddyfile or JSON config:
http://localhost:2020/www* {
root www
uri strip_prefix /www
file_server
handle_errors {
rewrite * /404.html
file_server
}
}
The www
folder contains two files: index.html
and 404.html
3. The problem I’m having:
The handle_errors
directive is ignore. There is no error message or warning.
5. What I already tried:
It took me a day of trial and error to understand what was happening. I found that adding another site without a path and with the handle_errors
directive fixes the problem.
http://localhost:2020/www* {
root www
uri strip_prefix /www
file_server
handle_errors {
rewrite * /404.html
file_server
}
}
http://localhost:2020 {
handle_errors {
rewrite * /404.html
file_server
}
}