Skip to content

Commit 1b7b2ad

Browse files
committed
document configuration of custom HTTP answers
1 parent 88547a5 commit 1b7b2ad

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

bin/config.toml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,24 @@ address = "0.0.0.0:8080"
164164
# this option is incompatible with expect_proxy
165165
# public_address = "1.2.3.4:80"
166166

167-
# path to custom 404 and 503 answers
167+
# For details about custom HTTP answers, see `doc/configure.md`,
168+
# and for defaults, check out `/lib/src/protocol/kawa_h1/answers.rs`
169+
# a 401 response is sent when a frontend has a Deny rule
170+
# answer_401 = "/absolute/path/to/custom_401.http"
168171
# a 404 response is sent when sozu does not know about the requested domain or path
172+
# answer_404 = "/absolute/path/to/custom_404.http"
173+
# a 408 response is sent when a frontend has a Deny rule (unusual)
174+
# answer_408 = "/absolute/path/to/custom_408.http"
175+
# a 413 response is sent when a request was too large
176+
# answer_413 = "/absolute/path/to/custom_413.http"
177+
# a 502 response means the response sent by a backend could not be parsed by Sōzu
178+
# answer_502 = "/absolute/path/to/custom_502.http"
169179
# a 503 response is sent if there are no backend servers available
170-
#answer_404 = "../lib/assets/404.html"
171-
#answer_503 = "../lib/assets/503.html"
180+
# answer_503 = "/absolute/path/to/custom_503.http"
181+
# a 504 response means the backend timed out
182+
# answer_504 = "/absolute/path/to/custom_504.http"
183+
# a 507 response occurs when the response sent by a backend is too big
184+
# answer_507 = "/absolute/path/to/custom_507.http"
172185

173186
# defines the sticky session cookie's name, if `sticky_session` is activated for
174187
# a cluster. Defaults to "SOZUBALANCEID"
@@ -189,9 +202,8 @@ address = "0.0.0.0:8443"
189202
# this option is incompatible with expect_proxy
190203
# public_address = "1.2.3.4:80"
191204

192-
# answer_404 = "../lib/assets/404.html"
193-
# answer_503 = "../lib/assets/503.html"
194-
answer_502 = "./502.html"
205+
# custom HTTP answers can be added here, see example config above
206+
195207
# sticky_name = "SOZUBALANCEID"
196208

197209
# Configures the client socket to receive a PROXY protocol header

doc/configure.md

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,65 @@ address = "0.0.0.0:8080"
8181

8282
#### Options specific to HTTP and HTTPS listeners
8383

84+
Since version 1.0.0, Sōzu allows custom HTTP answers defined for HTTP and HTTPS listeners.
85+
86+
These answers are customizable:
87+
88+
- 301 Moved Permanently
89+
- 400 Bad Request
90+
- 401 Unauthorized
91+
- 404 Not Found
92+
- 408 Request Timeout
93+
- 413 Payload Too Large
94+
- 502 Bad Gateway
95+
- 503 Service Unavailable
96+
- 504 Gateway Timeout
97+
- 507 Insufficient Storage
98+
99+
These answers are to be provided in plain text files of whichever extension (we recommend `.http`
100+
for clarity) and may look like this:
101+
102+
```html
103+
HTTP/1.1 404 Not Found
104+
Cache-Control: no-cache
105+
Connection: close
106+
Sozu-Id: %REQUEST_ID
107+
108+
<style>pre{background:#EEE;padding:10px;border:1px solid #AAA;border-radius: 5px;}</style>
109+
<h1>404 Not Found</h1>
110+
111+
<p>insert your custom text here, in fact, all HTML is changeable, including the CSS.</p>
112+
113+
<pre>
114+
{
115+
\"route\": \"%ROUTE\",
116+
\"request_id\": \"%REQUEST_ID\",
117+
}
118+
</pre>
119+
<footer>This is an automatic answer by Sozu.</footer>",
120+
```
121+
122+
There are a number of available template variables, like `REQUEST_ID` or `CLUSTER_ID`, that will be replaced
123+
by the proxying logic when producing the error.
124+
125+
To create your own custom HTTP answers, we highly suggest you first copy the default answers present
126+
in `lib/src/protocol/kawa_h1/answers.rs`, and then change them to your liking. Feel free to remove the
127+
`\r` newlines of the default strings for clarity.
128+
Sōzu will parse your file and replace whatever newline symbol(s) you use.
129+
130+
Then, for each listener, provide the absolute paths of each custom answer.
131+
84132
```toml
85-
# path to custom 404 and 503 answers
86133
# a 404 response is sent when sozu does not know about the requested domain or path
134+
answer_404 = "/path/to/my-404-answer.http"
87135
# a 503 response is sent if there are no backend servers available
88-
answer_404 = "../lib/assets/404.html"
89-
answer_503 = "../lib/assets/503.html"
136+
answer_503 = "/path/to/my-503-answer.http"
137+
# answer_507 = ...
138+
```
90139

140+
If a frontend has a `sticky_session`, the sticky name is defined at the listener level.
141+
142+
```toml
91143
# defines the sticky session cookie's name, if `sticky_session` is activated format
92144
# a cluster. Defaults to "SOZUBALANCEID"
93145
sticky_name = "SOZUBALANCEID"

0 commit comments

Comments
 (0)