Handle errors for custom 404 page

1. The problem I’m having:

I can’t have the errors handle to work on my caddyfile.
I tried adding
‘’’
handle_errors {
@404 {
expression {http.error.status_code} == 404
}
rewrite @404 /404.html
}
‘’’

2. Error messages and/or full log output:

I have the default 404 error even if I have a 404.html page made with hugo

3. Caddy version:

Caddyserver v2.6.4 h1 on Docker

4. How I installed and ran Caddy:

Caddyserver2 is running on docker with a docker-compose file

a. System environment:

VPS Linux Ubuntu 20.04.5 LTS

d. My complete Caddy config:

{
    email MY@gmail.com
}

www.officinecartografiche.net, officinecartografiche.net {

root * /website
file_server
encode gzip

}


portainer.officinecartografiche.net {
    reverse_proxy portainer:9000
}

cloud.officinecartografiche.net {
   reverse_proxy owncloud-server:8092
}


lizmap.officinecartografiche.net {
   reverse_proxy lizmap_web_1:8080
}

See the docs for handle_errors:

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.

You haven’t shown your logs as requested by the help topic template.

thanks, I did followed the docs and added

www.officinecartografiche.net, officinecartografiche.net {

root * /website
file_server
encode gzip
handle_errors {
   rewrite * /{http.error.status_code}.html
   file_server
 }
}

But still not working

Again, you haven’t shown your logs. Saying it’s “not working” is meaningless without detail. We can’t read your mind. Be specific, explain exactly the behaviour you’re seeing.

Sorry, I was having trouble identifying the log file and while testing I restarted the server and it works. now. thanks for your help

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.