1. Caddy version (caddy version
):
2.4.6
2. How I run Caddy:
Installed like officially recommended (cloudsmith). Ubuntu 20.04.
No changes or divergences from the official scripts.
d. My complete Caddyfile or JSON config:
(errorpages) {
handle_errors {
@404 expression `{http.error.status_code} == 404`
@403 expression `{http.error.status_code} == 403`
@generic_error expression `({http.error.status_code} != 403 && {http.error.status_code} != 404)`
root * /var/www/handle_errors
rewrite @404 /404.html
rewrite @403 /403.html
rewrite @generic_error /generic.html
templates
file_server
}
}
www.example.com {
root * /var/www/mautic
import errorpages
encode zstd gzip
php_fastcgi 127.0.0.1:9000 {
@error status 500 503
handle_response @error {
#copy_response_headers @error {
#include status
#}
root * /var/www/handle_errors
rewrite * /generic.html
header Status {http.reverse_proxy.status_code}
file_server
}
}
file_server
}
3. The problem I’m having:
I can’t figure out how to return the proper HTTP Error Status (5xx) when my PHP scripts throw an error, using php_fastcgi. Currently I see HTTP Status 200 on the response with the given config above.
4. Error messages and/or full log output:
No errors. Only when playing with “copy_response_headers” I see:
Error during parsing: unrecognized directive: copy_response_headers - are you sure your Caddyfile structure (nesting and braces) is correct?
which might be caused by me using it wrong or some caddyfile/json thing
5. What I already tried:
Adding the status code with the “header” directive myself (see config).
The documentation on “handle_errors” tells:
Note that certain directives, for example
reverse_proxy
which may write a response with an HTTP status which is classified as an error, will not trigger the error routes.
I was glad to find out I can pass thru some directives within php_fastcgi and went that road but still can’t figure out the right way to use it. It somehow works because my errorpages snippet is used.
How can I make the status code “survive” so that the errorpages snippet can work with it?