Skip to main content

Custom Error Pages

Aegis renders branded error pages when the upstream returns an error or is unreachable. Each proxy host can define status-specific HTML templates, branding, and contact information — or use the built-in default template.
Image

Features

FeatureDetails
Per-host configurationEach proxy host has its own error page settings
Status-specific templatesCustom HTML for 502, 503, and 504 with a generic fallback
Template variablesDynamic substitution of status code, incident ID, timestamp, host, and branding
CSS and JavaScript injectionSeparate CSS and JS fields injected into the template document
BrandingConfigurable brand name, logo URL, and accent color
Contact informationOptional contact email and reporting URL
Metadata displayToggle incident ID and timestamp visibility
Security headersError responses include the same security headers as normal responses
HSTSError responses respect per-host HSTS configuration
Request IDAegis request ID is included in the response headers

How It Works

When custom error pages are enabled for a host and the response status is 400 or higher:
  1. Aegis selects the template matching the status code (502, 503, 504) or falls back to the generic template
  2. If a custom template exists, Aegis renders it with variable substitution and CSS/JS injection
  3. If no custom template exists, Aegis renders the built-in default error page with the host’s branding settings
  4. The original upstream response body is replaced with the rendered error page

Configuration

Error page configuration is stored as part of the proxy host settings:
SettingTypeDescription
enabledbooleanEnable custom error pages for this host
custom_502templateCustom template for 502 Bad Gateway
custom_503templateCustom template for 503 Service Unavailable
custom_504templateCustom template for 504 Gateway Timeout
custom_generictemplateFallback template for all other error status codes
contact_emailstringSupport email address displayed on the error page
contact_urlstringURL for reporting issues
show_incident_idbooleanDisplay the Aegis request ID on the error page
show_timestampbooleanDisplay the error timestamp
brand_namestringBrand name displayed on the error page
brand_logo_urlstringLogo URL (https:// or data:image/ URI)
accent_colorstringCSS color value for the accent color (default: #ef4444)
Each template object contains three fields:
FieldTypeDescription
htmlstringHTML content (full document or fragment)
cssstringCSS injected into <head>
javascriptstringJavaScript injected before </body>

Template Variables

Custom templates support variable substitution in two formats:
VariableAliasDescription
${{code}}{{STATUS_CODE}}HTTP status code (e.g., 502)
${{message}}{{STATUS_TEXT}}HTTP status text (e.g., Bad Gateway)
${{incident_id}}{{INCIDENT_ID}}Aegis request ID for support reference
${{timestamp}}{{TIMESTAMP}}Error timestamp in RFC 3339 format
${{host}}{{HOST}}Proxy host domain
${{brand}}Configured brand name
${{logo}}Configured brand logo URL
${{contact_email}}Configured contact email
${{contact_url}}Configured contact URL

Template Rendering

Aegis handles two template formats:

Full HTML Documents

If the HTML contains <html, <head, or <body tags, Aegis treats it as a full document:
  • CSS is injected as a <style> block before </head>
  • JavaScript is injected as a <script> block before </body>

HTML Fragments

If the HTML is a fragment (no document structure), Aegis wraps it in a proper document with <meta charset> and viewport tags, injecting CSS and JS in the appropriate locations.

Default Template

When no custom template matches the status code, Aegis renders a built-in error page with the following design:
  • Dark theme with radial gradient background
  • Glassmorphic panel design (backdrop blur, semi-transparent background)
  • Large status code display with configurable accent color
  • Status text and human-readable error description
  • Metadata pills for host, incident ID, and timestamp
  • Contact email and issue-reporting link
  • Responsive layout (max width 640px)
  • IBM Plex Sans / Segoe UI font stack
The default template respects all branding settings — brand name, logo, accent color, and contact information are applied automatically.

Template Selection

Aegis selects templates in the following priority order:
  1. Status-specific templatecustom_502, custom_503, or custom_504 if it has content
  2. Generic templatecustom_generic if it has content
  3. Default template — built-in Aegis error page with host branding
A template is considered to have content if any of its html, css, or javascript fields are non-empty.

Security

  • Logo URL sanitization — only https://, http://, and data:image/ URIs are allowed; all other schemes are rejected
  • Contact URL sanitization — only http:// and https:// URLs are allowed
  • Security headers — error responses include the same security headers configured for the host
  • HSTS — error responses include Strict-Transport-Security if enabled for the host
  • Response cleanupContent-Encoding, Content-Range, ETag, and Last-Modified headers are stripped from replaced responses

Error Status Mapping

When the upstream is unreachable, Aegis maps the proxy error to the appropriate status:
Error typeStatus code
Context deadline exceeded504 Gateway Timeout
Network timeout504 Gateway Timeout
All other errors502 Bad Gateway