Default page on domain not found


(Eddie) #1

How can i change the default 404 page when the domain is not found?
I’m using multiple domain configurations but there doe not seem to be a place to add a default error page.


(Matthew Fay) #2

Hi @eddie,

You can designate a static HTML file to be served when a specific error status is issued.

Check out the errors directive - one of the examples demonstrates custom error pages for 404s and 500s:

https://caddyserver.com/docs/errors#examples


(Eddie) #3

I know that but i have multiple domains.
so if i test with

errors {
    404 /data/storage/serv/404.html
    500 /data/storage/serv/500.html
}


example.com {
    filemanager
}

it gives an error:

caddy.conf:2 - Error during parsing: Unknown directive ‘404’

But i already figured it out, you need to wrap it in 0.0.0.0, so it listens for all

0.0.0.0 {
    errors {
        404 /data/storage/serv/404.html
        500 /data/storage/serv/500.html
    }
}


example.com {
    filemanager
}

I leave this here so someone else may find it usefull.

–edit: formatting


(Matthew Fay) #4

As per the Caddyfile documentation:

https://caddyserver.com/docs/caddyfile#structure

The first item of every Caddyfile must be the site name, and with multiple sites, you must open a brace block after the labels for that site. With your first test, Caddy thinks “errors” is the hostname of your website, and “404” / “500” are directives (which they aren’t, causing the error you received).

There’s also a few caveats to your last example:

  1. The default port is 2015, so a site listening on 0.0.0.0 should only respond if you browse to your server on that port. A better catch-all might be just :80 {errors ...}.
  2. Being a catch-all, and the fact that Caddy matches a single site, your custom error pages will only work if the site accessed is not example.com. That might be your intention, but it’s an important distinction for people who might want their custom error pages on all their sites. To do that, you’d have to put the errors directive once in each site block you have in your Caddyfile.

(system) #5

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