1
+ ** [ Install] ( #install ) ** |
2
+ ** [ Using configurable-http-proxy] ( #using-configurable-http-proxy ) ** |
3
+ ** [ Using the REST API] ( #using-the-rest-api ) ** |
4
+ ** [ Custom error pages] ( #custom-error-pages ) ** |
5
+ ** [ Host-based routing] ( #host-based-routing ) **
6
+
1
7
# configurable-http-proxy
2
8
3
9
[ ![ Build Status] ( https://travis-ci.org/jupyterhub/configurable-http-proxy.svg?branch=master )] ( https://travis-ci.org/jupyterhub/configurable-http-proxy )
@@ -19,11 +25,14 @@ node-http-proxy to provide this functionality to JupyterHub.
19
25
20
26
## Install
21
27
22
- To install ` configurable-http-proxy ` globally using the npm package manager:
28
+ Prerequisite: [ Node.js] ( https://nodejs.org/en/download/ )
29
+
30
+ To install globally from the ` configurable-http-proxy ` package release
31
+ using the npm package manager:
23
32
24
33
npm install -g configurable-http-proxy
25
34
26
- To install from source found in this GitHub repo:
35
+ To install from the source code found in this GitHub repo:
27
36
28
37
git clone https://github.com/jupyterhub/configurable-http-proxy.git
29
38
cd configurable-http-proxy
@@ -41,10 +50,13 @@ The configurable proxy runs two HTTP(S) servers:
41
50
localhost by default. The REST API uses token authorization, set by the
42
51
` CONFIGPROXY_AUTH_TOKEN ` environment variable.
43
52
44
- When you start the proxy, you can set a default target to be used when no
53
+ ### Setting a default target
54
+
55
+ When you start the proxy from the command line, you can set a
56
+ default target (` --default-target ` option) to be used when no
45
57
matching route is found in the proxy table:
46
58
47
- $ configurable-http-proxy --default-target=http://localhost:8888
59
+ configurable-http-proxy --default-target=http://localhost:8888
48
60
49
61
### Command-line options
50
62
@@ -57,6 +69,7 @@ matching route is found in the proxy table:
57
69
-V, --version output the version number
58
70
--ip <ip-address> Public-facing IP of the proxy
59
71
--port <n> (defaults to 8000) Public-facing port of the proxy
72
+
60
73
--ssl-key <keyfile> SSL key to use, if any
61
74
--ssl-cert <certfile> SSL certificate to use, if any
62
75
--ssl-ca <ca-file> SSL certificate authority, if any
@@ -66,13 +79,15 @@ matching route is found in the proxy table:
66
79
--ssl-ciphers <ciphers> `:`-separated ssl cipher list. Default excludes RC4
67
80
--ssl-allow-rc4 Allow RC4 cipher for SSL (disabled by default)
68
81
--ssl-dhparam <dhparam-file> SSL Diffie-Helman Parameters pem file, if any
82
+
69
83
--api-ip <ip> Inward-facing IP for API requests
70
84
--api-port <n> Inward-facing port for API requests (defaults to --port=value+1)
71
85
--api-ssl-key <keyfile> SSL key to use, if any, for API requests
72
86
--api-ssl-cert <certfile> SSL certificate to use, if any, for API requests
73
87
--api-ssl-ca <ca-file> SSL certificate authority, if any, for API requests
74
88
--api-ssl-request-cert Request SSL certs to authenticate clients for API requests
75
89
--api-ssl-reject-unauthorized Reject unauthorized SSL connections (only meaningful if --api-ssl-request-cert is given)
90
+
76
91
--default-target <host> Default proxy target (proto://host[:port])
77
92
--error-target <host> Alternate server for handling proxy errors (proto://host[:port])
78
93
--error-path <path> Alternate server for handling proxy errors (proto://host[:port])
@@ -89,19 +104,29 @@ matching route is found in the proxy table:
89
104
--log-level <loglevel> Log level (debug, info, warn, error)
90
105
```
91
106
107
+
92
108
## Using the REST API
93
109
94
- The REST API is authenticated via a token in the ` Authorization ` header.
95
- The API is served under the ` /api/routes ` base URL. For example:
110
+ The configurable-http-proxy API is documented and available at the
111
+ interactive swagger site, [ petstore] ( http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyterhub/configurable-http-proxy/master/doc/rest-api.yml#/default )
112
+ or as a [ swagger specification file in this repo] ( https://github.com/jupyterhub/configurable-http-proxy/blob/master/doc/rest-api.yml ) .
113
+
114
+ ### Authenticating via passing a token
96
115
97
- $> curl -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" http://localhost:8001/api/routes
116
+ The REST API is authenticated via passing a token in the ` Authorization ` header.
117
+ The API is served under the ` /api/routes ` base URL. For example, execute
118
+ this ` curl ` command in the terminal to authenticate and retrieve the
119
+ current routing table:
98
120
121
+ curl -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" http://localhost:8001/api/routes
99
122
100
123
### Getting the current routing table
101
124
125
+ ** Request**
126
+
102
127
GET /api/routes[?inactive_since=ISO8601-timestamp]
103
128
104
- Returns a JSON dictionary of the current routing table.
129
+ The GET request returns a JSON dictionary of the current routing table.
105
130
106
131
This JSON dictionary * excludes* the default route. If the ` inactive_since ` URL
107
132
parameter is given as an [ ISO8601] ( http://en.wikipedia.org/wiki/ISO_8601 )
@@ -110,8 +135,11 @@ will be returned.
110
135
111
136
** Response**
112
137
138
+ Status code:
139
+
113
140
status: 200 OK
114
141
142
+ Returned JSON dictionary of current routing table:
115
143
116
144
``` json
117
145
{
@@ -129,69 +157,84 @@ will be returned.
129
157
The ` last_activity ` timestamp is updated whenever the proxy passes data to
130
158
or from the proxy target.
131
159
132
-
133
160
### Adding new routes
134
161
135
162
POST requests create new routes. The body of the request should be a JSON
136
163
dictionary with at least one key: ` target ` , the target host to be proxied.
137
164
165
+ ** Request**
166
+
138
167
POST /api/routes/[:path]
139
168
140
- ** Input* *
169
+ * Input - request body *
141
170
142
171
` target ` : The host URL
143
172
144
173
** Response**
145
174
146
175
status: 201 Created
147
176
148
- Any request to ` /path/prefix ` on the proxy's public interface will be proxied
149
- to ` target ` .
177
+ After adding the new route, any request to ` /path/prefix ` on the proxy's
178
+ public interface will be proxied to ` target ` .
150
179
151
180
### Deleting routes
152
181
182
+ ** Request**
183
+
153
184
DELETE /api/routes/[:path]
154
185
155
186
** Response**
156
187
157
188
status: 204 No Content
158
189
190
+ Removes a route from the proxy's routing table.
191
+
192
+
159
193
## Custom error pages
160
194
161
195
With version 0.5, configurable-host-proxy (CHP) adds two ways to provide
162
196
custom error pages when the proxy encounters an error, and has no proxy target
163
- to handle a request. There are two typical errors that CHP can hit:
197
+ to handle a request. There are two typical errors that CHP can hit, along
198
+ with their status code:
164
199
165
200
- 404: a client has requested a URL for which there is no routing target.
166
- This is impossible if a default target has been specified.
201
+ This can be prevented if a ` default target ` is specified when starting
202
+ the configurable-http-proxy.
167
203
168
204
- 503: a route exists, but the upstream server isn't responding.
169
205
This is more common, and can be due to any number of reasons,
170
206
including the target service having died or not finished starting.
171
207
172
208
### error-path
173
209
174
- If you specify ` --error-path /usr/share/chp-errors ` , then when a proxy error
175
- occurs, CHP will look in ` /usr/share/chp-errors/CODE.html ` for an html page
176
- to serve, e.g. ` 404.html ` or ` 503.html ` .
210
+ If you specify an error path ` --error-path /usr/share/chp-errors ` when
211
+ starting the CHP:
212
+
213
+ configurable-http-proxy --error-path /usr/share/chp-errors
214
+
215
+ then when a proxy error occurs, CHP will look in
216
+ ` /usr/share/chp-errors/<CODE>.html ` (where CODE is the status code number)
217
+ for an html page to serve, e.g. ` 404.html ` or ` 503.html ` .
177
218
178
219
If no file exists for the error code, ` error.html ` file will be used.
179
- If you use this approach , make sure you have created ` error.html ` .
220
+ If you specify an error path , make sure you also create ` error.html ` .
180
221
181
222
### error-target
182
223
224
+ When starting the CHP, you can pass a command line option for ` --error-target ` .
183
225
If you specify ` --error-target http://localhost:1234 ` ,
184
- then when the proxy encounters an error, it will make a GET request to this
185
- server, with URL ` /CODE ` , and the URL of the failing request escaped in a URL
186
- parameter, e.g.:
226
+ then when the proxy encounters an error, it will make a GET request to
227
+ this server, with URL ` /CODE ` , and the URL of the failing request
228
+ escaped in a URL parameter, e.g.:
187
229
188
230
GET /404?url=%2Fescaped%2Fpath
189
231
190
232
191
233
## Host-based routing
192
234
193
- If ` --host-routing ` is given, the proxy will pick a target based on the host
194
- of the incoming request, instead of the URL prefix.
235
+ If the CHP is started with the ` --host-routing ` option, the proxy will
236
+ pick a target based on the host of the incoming request, instead of the
237
+ URL prefix.
195
238
196
239
The API when using host-based routes is the same as if the hostname were the
197
240
first part of the URL path, e.g.:
0 commit comments