1. Caddy version (caddy version
):
v2.3.0
2. How I run Caddy:
sudo systemctl start caddy
a. System environment:
Ubuntu 20.04
PHP 7.4.3
php7.4-fpm
b. Command:
sudo systemctl reload caddy
sudo systemctl restart caddy
c. Service/unit/compose file:
n/a
d. My complete Caddyfile or JSON config:
root * /home/my/project/
log {
output file /var/log/caddy/access.log {
roll_size 3MiB
roll_keep 10
roll_keep_for 2160h
}
format json
}
@cachedFiles {
path *.jpg, *.jpeg, *.png, *.gif, *.ico, *.woff, *.woff2, *.ttf
}
header @cachedFiles Cache-Control "public, max-age=604800, must-revalidate"
encode gzip zstd
handle_errors {
respond "{http.error.status_code} {http.error.status_text}"
# rewrite * /{http.error.status_code}.php
# php_fastcgi unix//run/php/php7.4-fpm.sock
# file_server
}
php_fastcgi unix//run/php/php7.4-fpm.sock
file_server
}
3. The problem I’m having:
I am attempting to catch any 500 errors so that I can:
- Notify our team via email/text
- Provide a nice message to our clients
The issue seems to be that handle_errors does not capture 500 errors. I can catch 404 errors and create a nice page for our clients to digest. 500 errors always return a blank page. The only way not to receive a blank page is to set the display_errors = On in the php.ini file, and though that is great in development, I don’t want to air our dirty laundry to the world. In addition, the error sent back via display_errors will not allow me to customize the message. I just receive a PHP error:
( ! ) Parse error: syntax error, unexpected end of file in /home/my/project/admin/all.php on line 53
4. Error messages and/or full log output:
n/a (blank page)
5. What I already tried:
I have tried specifically catching 500 errors
@404 {
expression {http.error.status_code} == 404
}
respond @404 "four oh Four"
@500 {
expression {http.error.status_code} == 500
}
respond @500 "busted"
One thing to note, when I do set the display_errors = On in the php.ini file, the log file returned by caddy results in a 200, not a 500 error. If display_errors = Off, then caddy returns a 500 error, but it will not redirect, respond, or rewrite as anticipated.