All Collections › SSL, Load Balancers & Caddy › Custom Error and Maintenance Pages

Custom Error and Maintenance Pages

Show your own pages while your app is down or in maintenance mode, from a .hatchbox/templates folder in your repository.

By Chris Oliver · Updated

When your app can't answer a request, Caddy shows a page of its own instead. That happens while the app is restarting or down, when a load balancer has no healthy server to send a request to, and for every request while the app is in maintenance mode. Hatchbox puts a plain default page on each server, and you can replace it with your own by committing your pages to your repository.

Adding your pages

Create a .hatchbox/templates folder in your repository and add any of these:

  • maintenance.html, shown for every request while maintenance mode is on
  • error.html, shown when the app can't answer
  • A page named for a status code, like 502.html, 503.html or 504.html, shown instead of error.html for that status
.hatchbox/
templates/
maintenance.html
error.html
502.html

Commit and deploy. Each deploy reads the folder from the commit it deploys and puts the pages on every server that serves the app, including load balancers and servers you add later. This works on both native and Dockerfile clusters. If your app lives in a subdirectory of the repository, put the folder in that subdirectory.

When you change a page, the next deploy updates it on every server. Remove the folder, and the next deploy goes back to the server's own pages.

Which page is shown

For an error, Caddy uses the first of these that exists:

  1. Your page for the status code, like 502.html
  2. Your error.html
  3. The server's page for the status code in /home/deploy/.hatchbox/templates
  4. The server's error.html

In maintenance mode, Caddy serves your maintenance.html, or the server's if you don't have one. It's served with a 503 status and a Retry-After header, so search engines know to come back later.

These pages only cover errors where your app never answered. An error page your app renders itself, like the 500 page Rails shows when an exception is raised, passes straight through to the visitor.

Writing the pages

Every request gets the same page whatever its path, and your app isn't there to serve stylesheets or images. Keep each page self-contained: put CSS in a <style> tag and inline images as data URIs, or load them from another host.

Commit the finished HTML. Hatchbox reads the pages from git, not from your built app, so a page generated by your build or a deploy script isn't picked up.

A few limits apply:

  • Only the file names above are used. Other files in the folder are ignored.
  • Each page must be a regular file, not a symlink, of UTF-8 text.
  • Each page can be up to 256 KB, and all of them together up to 1 MB.

A page that breaks one of these is left out, with a warning in the deploy log, and the server's own page is used instead.

Turning on maintenance mode

Open your app's Settings and, under General, click Enable next to Maintenance Mode. Caddy serves the maintenance page on every server until you click Disable.

Server-wide pages

The server's own pages are in /home/deploy/.hatchbox/templates on each server, and they're used for every app on that server without pages of its own. You can still edit them over SSH, but your repository is the better place for your own design. A page you edit by hand is only on that one server, while the pages in your repository reach every server the app runs on.