mirror of
https://github.com/caddyserver/website.git
synced 2025-05-06 11:47:12 -04:00
docs: Add basicauth example for when pairing with handle_errors
This commit is contained in:
parent
6518711538
commit
2f3cfafd76
2 changed files with 17 additions and 1 deletions
|
@ -41,3 +41,19 @@ basicauth /secret/* {
|
|||
}
|
||||
```
|
||||
|
||||
If you're also using [`handle_errors`](handle_errors) (for example to change how a `502` error from [`reverse_proxy`](reverse_proxy) is displayed), then make sure to use [`respond`](respond) to write the HTTP status, since the HTTP status is not written automatically when using error handlers.
|
||||
|
||||
```caddy-d
|
||||
handle_errors {
|
||||
# The reverse_proxy handler had no upstream to proxy to,
|
||||
# and we want to display a custom 502 page in that case
|
||||
@out-of-order expression `{http.error.status_code} == 502`
|
||||
handle @out-of-order {
|
||||
rewrite * /502.html
|
||||
file_server
|
||||
}
|
||||
|
||||
# Write the HTTP status code from basicauth (i.e. 401)
|
||||
respond {http.error.status_code}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -29,7 +29,7 @@ handle_errors {
|
|||
|
||||
## Examples
|
||||
|
||||
Custom error pages based on the status code (i.e. a page called `404.html` for 404 errors):
|
||||
Custom error pages based on the status code (i.e. a page called `404.html` for 404 errors). Note that [`file_server`](file_server) preserves the error's HTTP status code when run in `handle_errors`:
|
||||
|
||||
```caddy-d
|
||||
handle_errors {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue