Custom Error Pages
Configure custom HTML error pages to provide branded, user-friendly responses when errors occur.
Overview
GoDoxy supports custom error pages for HTTP status codes. When an error occurs, GoDoxy will serve your custom page instead of generic browser error pages. This feature is useful for:
- Maintaining consistent branding across error responses
- Providing helpful guidance to users when errors occur
- Supporting multiple languages or themes
- Integrating with your application's design system
Quick Start
- Create an
error_pagesdirectory in your project - Add HTML files named after status codes (e.g.,
404.html,500.html) - Mount the directory to
/app/error_pagesin the GoDoxy container
Directory Structure
All error page files must reside in the root of the error_pages directory. Subdirectories are not supported.
project/
├── error_pages/
│ ├── 400.html
│ ├── 403.html
│ ├── 404.html
│ ├── 500.html
│ ├── 502.html
│ ├── 503.html
│ └── style.css
└── docker-compose.ymlConfiguration
Docker Mount
Mount your error pages directory to the GoDoxy container:
services:
godoxy:
image: godoxy:latest
container_name: godoxy
volumes:
- ./error_pages:/app/error_pages
- ./config.yaml:/app/config.yaml:ro
ports:
- '80:80'
- '443:443'File Naming Convention
Error pages must be named using the HTTP status code:
| File | HTTP Status |
|---|---|
400.html | Bad Request |
403.html | Forbidden |
404.html | Not Found |
500.html | Internal Server Error |
502.html | Bad Gateway |
503.html | Service Unavailable |
Asset References
Use the /$gperrorpage/ prefix for all relative asset paths. This ensures assets load correctly regardless of the original request URL.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Page Not Found</title>
<link rel="stylesheet" href="/$gperrorpage/style.css" />
<script src="/$gperrorpage/app.js" defer></script>
</head>
<body>
<div class="error-container">
<h1>404</h1>
<p>The page you're looking for doesn't exist.</p>
<a href="/">Go Home</a>
</div>
</body>
</html>Supported Asset Types
- CSS files (
<link rel="stylesheet">) - JavaScript files (
<script src="...">) - Images (
<img src="...">) - Fonts (
@font-face,font-family) - Favicons (
<link rel="icon">)
Serving Conditions
Custom error pages are served when:
- Route Not Found: The requested route doesn't exist in your configuration
- Domain Mismatch: The request domain doesn't match configured
match_domains - HTTP Error Status: Response status code is outside 200-299 range
- Supported Content Types: Error pages apply to:
text/htmlapplication/xhtml+xmltext/plain
- Middleware: Configured as a middleware for specific routes
Priority Order
GoDoxy checks for error pages in this order:
- Exact match:
<statusCode>.html(e.g.,503.html) - Fallback:
404.html - Original response: If no custom page exists
Hot Reload
Error pages support hot reload during development. Changes to files in the error_pages directory apply immediately on page refresh.
Best Practices
Include Useful Information
Help users understand what happened and what to do next:
<div class="error-content">
<h1>Something went wrong</h1>
<p>We're working on fixing this issue.</p>
<p>Try again in a few minutes or <a href="/contact">contact support</a>.</p>
</div>Maintain Branding
Keep error pages consistent with your application's design:
/* Match your app's color scheme */
:root {
--primary-color: #3b82f6;
--text-color: #1f2937;
}
.error-container {
color: var(--text-color);
}Keep Pages Lightweight
Error pages may be served when resources are unavailable. Avoid heavy dependencies:
- Minimal JavaScript
- Inline critical CSS
- Avoid external CDN dependencies
Troubleshooting
Assets Not Loading
Ensure all asset paths use the /$gperrorpage/ prefix:
<!-- ❌ Incorrect -->
<link rel="stylesheet" href="/css/style.css" />
<!-- ✅ Correct -->
<link rel="stylesheet" href="/$gperrorpage/style.css" />Error Page Not Showing
- Verify the file exists in the correct location
- Check the file name matches the HTTP status code
- Ensure the volume mount is correct
- Confirm the content type is supported
Subdirectories Not Supported
Place all error page files directly in error_pages/:
error_pages/
├── 404.html ✅
├── 500.html ✅
└── errors/ ❌
└── 404.html // Not detected