Default web server error pages are generic and unbranded. Custom error pages improve user experience during outages or broken links, and can guide visitors back to useful content instead of a dead end.
Why Custom Error Pages Matter
A well-designed 404 page can retain a visitor who hit a broken link (by offering search or navigation back to your site) rather than simply displaying a bare "Not Found" and losing them entirely.
Common Error Codes Worth Customizing
| Code | Meaning |
|---|---|
| 404 | Page not found |
| 500 | Internal server error |
| 502/503/504 | Backend/gateway errors, often during deployments or outages |
| 403 | Forbidden/access denied |
Step 1 — Create Your Custom Error Page(s)
sudo mkdir -p /var/www/errors
sudo nano /var/www/errors/404.html
Design a page matching your site's branding, ideally including navigation links and perhaps a search box to help lost visitors find what they need.
Step 2 — Configure Nginx
server {
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /404.html {
root /var/www/errors;
internal;
}
location = /50x.html {
root /var/www/errors;
internal;
}
}
internal prevents these error page URLs from being directly accessible by visitors, reserving them purely for error handling.
Step 3 — Configure Apache
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
Step 4 — Test
curl -I https://yourdomain.com/this-page-does-not-exist
Verify a 404 status is returned, then visit the URL in a browser to confirm your custom page displays correctly.
Handling 502/503/504 Pages for Backend Outages
These pages are especially important since they appear during actual outages/deployments — keep them simple, static (not dependent on any backend that might itself be down), and reassuring, letting visitors know the issue is known and being addressed.
Making Error Pages Genuinely Static
Ensure custom error pages don't depend on your application/database being available — a 500-error page that itself requires a database connection is useless precisely when it's needed most (during a database outage).
Including Useful Content on the 404 Page
- A search box or link to search functionality
- Links to popular/main site sections
- A brief, friendly explanation rather than technical jargon
SEO Considerations for 404 Pages
Ensure your custom 404 page still returns an actual 404 HTTP status code (not 200) — a "soft 404" (custom page content but with a 200 status) confuses search engines into potentially indexing broken URLs as if they were valid content.
Common Errors
Custom error page doesn't display, default page shows instead — verify the file path in the configuration exactly matches where the custom page actually exists, and check for typos in the error_page/ErrorDocument directive.
Continue Reading
- How to Fix Common Nginx Errors (502/504/403)
- How to Fix Common Apache Errors (500/403/AH Errors)
- How to Build a Status Page for Your Service
Browse more articles in Web Servers.