1. Output of caddy version
:
v2.6.1
2. How I run Caddy:
a. System environment:
Arch Linux, systemd
b. Command:
caddy run
c. Service/unit/compose file:
d. My complete Caddy config:
localhost
root * projects/test/dist
file_server
encode gzip
try_files {path}.html {path}
try_files {path} {path}/ =404
handle_errors {
file_server
templates
rewrite error
}
3. The problem I’m having:
In the docs, in handle_error
Examples section it says:
A single error page that uses templates to write a custom error message:
handle_errors { rewrite * /error.html templates file_server }
But there is nothing said about what should be put in the html, I tried using {{err.status_code}} {{err.status_text}}
but that didn’t work.
4. Error messages and/or full log output:
2022/10/23 20:40:40.344 ERROR http.log.error error handling handler error {"request": {"remote_ip": "127.0.0.1", "remote_port": "47560", "proto": "HTTP/2.0", "method": "GET", "host": "localhost", "uri": "/favicon.ico", "headers": {"User-Agent": ["Mozilla/5.0 (X11; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0"], "Accept": ["image/avif,image/webp,*/*"], "Accept-Language": ["en-US,en;q=0.5"], "Dnt": ["1"], "Referer": ["https://localhost/favicon.ico"], "Sec-Fetch-Dest": ["image"], "Cache-Control": ["no-cache"], "Accept-Encoding": ["gzip, deflate, br"], "Sec-Fetch-Mode": ["no-cors"], "Sec-Fetch-Site": ["same-origin"], "Sec-Gpc": ["1"], "Pragma": ["no-cache"], "Te": ["trailers"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "server_name": "localhost"}}, "duration": 0.000096811, "error": "{id=a86n20jvi} templates.(*Templates).executeTemplate (templates.go:403): HTTP 500: template: error:12: function \"err\" not defined", "first_error": {"msg": "404", "status": 404, "err_id": "ag6e5qr23", "err_trace": "fileserver.parseErrorCode (matcher.go:489)"}}
5. What I already tried:
Finding the documentation for templates,
{{err.status_code}} {{err.status_text}}