Skip to content

Commit efc6575

Browse files
committed
Added examples / config for caddy
1 parent 3219c54 commit efc6575

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

CADDY.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# How to use in Caddy
2+
3+
This setup allows you to serve **custom error pages** in your Caddy server configuration using reusable **snippets** for both:
4+
5+
- **Upstream response errors** (e.g. Not found errors)
6+
- **General proxy/server errors** (e.g. Caddy-level issues)
7+
8+
## 📁 Error Pages
9+
Download the ZIP from [README.md](./README.md) and extract all html files into /errors (or anyo ther directory)
10+
11+
## 📦 Snippets
12+
Add the following two snippets at the top of your `Caddyfile`:
13+
14+
```caddyfile
15+
(upstream_error_handler) {
16+
@error status 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 500 501 502 503 504 505 506 507 508 509 510 511
17+
handle_response @error {
18+
root * /errors
19+
rewrite * /http-{rp.status_code}.html
20+
templates
21+
file_server
22+
}
23+
}
24+
25+
(proxy_error_handler) {
26+
handle_errors {
27+
root * /errors
28+
rewrite * /http-{err.status_code}.html
29+
templates
30+
file_server
31+
}
32+
}
33+
```
34+
35+
⚠️ Using **`templates`** can leak information such as internal URLs or IPs! USE WITH CAUTION!
36+
⚠️ Depending on your error directory, you might have to change the `root` directive in the Snippets!
37+
38+
## 🛠 How to Use
39+
Add the following imports into your `handler` or `reverse_proxy` blocks
40+
41+
```caddyfile
42+
example.com {
43+
import proxy_error_handler # Handles errors caused by the proxy (e.g. includes 501)
44+
45+
reverse_proxy http://localhost:8080 {
46+
import upstream_error_handler # Handles errors caused / returned from upstream
47+
}
48+
}
49+
```

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
## 📁 Download
88
Download the latest bundle from GitHub Pages Branch: [Download as ZIP](https://github.com/ToBiDi0410/error-pages/archive/refs/heads/gh-pages.zip)
99

10-
---
10+
11+
## 🛠 Usage
12+
- [How to use in Caddy](./CADDY.md)
1113

1214
## 🌐 Available Pages & Demo
1315
Here's a list of all available error pages and their demo links:

0 commit comments

Comments
 (0)