You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2
Original file line number
Diff line number
Diff line change
@@ -80,6 +80,8 @@ The following query arguments can be used to send as a *reconfigure* request to
80
80
|distribute |Whether to distribute a request to all the instances of the proxy. Used only in the *swarm* mode.|No|false|true|
81
81
|pathType |The ACL derivative. Defaults to *path_beg*. See [HAProxy path](https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#7.3.6-path) for more info.|No||path_beg|
82
82
|port |The internal port of a service that should be reconfigured. The port is used only in the *swarm* mode|Only in *swarm* mode|||8080|
83
+
|reqRepReplace|A regular expression to apply the modification. If specified, `reqRepSearch` needs to be set as well.|No||\1\ /demo/\2|
84
+
|reqRepSearch |A regular expression to search the content to be replaced. If specified, `reqRepReplace` needs to be set as well.|No||^([^\ ]\*)\ /something/(.\*)|
83
85
|serviceDomain|The domain of the service. If specified, the proxy will allow access only to requests coming to that domain. Multiple domains should be separated with comma (`,`).|No||ecme.com|
84
86
|serviceName |The name of the service. It must match the name of the Swarm service or the one stored in Consul.|Yes ||go-demo |
85
87
|servicePath |The URL path of the service. Multiple values should be separated with comma (`,`).|Yes (unless consulTemplatePath is present)||/api/v1/books|
Copy file name to clipboardExpand all lines: articles/swarm-mode-listener.md
+68-1
Original file line number
Diff line number
Diff line change
@@ -286,7 +286,7 @@ curl -i $(docker-machine ip node-1)/demo/hello
286
286
287
287
Since Docker's networking (`routing mesh`) is performing load balancing, each of those requests is sent to a different proxy instance. Each was forwarded to the `go-demo` service endpoint, Docker networking did load balancing and resent it to one of the `go-demo` instances. As a result, all requests returned status *200 OK* proving that the combination of the proxy and the listener indeed works. All three instances of the proxy were reconfigured.
288
288
289
-
Let's remove the `go-demo` service before we proceed.
289
+
Let's remove the `go-demo` service before we proceed with explanation of the flow.
290
290
291
291
```bash
292
292
docker service rm go-demo
@@ -314,12 +314,79 @@ One of the important things to note is that, with a system like this, everything
314
314
315
315
A similar logic is used for the destination services. The proxy does not need to do load balancing. Docker networking does that for us. The only thing it needs is the name of the service and that both belong to the same network. As a result, there is no need to reconfigure the proxy every time a new release is made or when a service is scaled.
316
316
317
+
## Rewriting Paths
318
+
319
+
In some cases, you might want to rewrite the path of the incoming request before forwarding it to the destination service. We can do that using request parameters `reqRepSearch` and `reqRepReplace`.
320
+
321
+
As an example, we'll create the `go-demo` service that will be configured in the proxy to accept requests with the path starting with `/something`. Since the `go-demo` service allows only requests that start with `/demo`, we'll use `reqRepSearch` and `reqRepReplace` to rewrite the path.
Please notice that, this time, the `servicePath` is `/something`. The `reqRepSearch` specifies the regular expression that will be used to search for part of the address and the `reqRepReplace` will replace it. In this case, `/something/` will be replaced with `/demo/`. The proxy uses *PCRE compatible regular expressions*. For more information, please consult [Quick-Start: Regex Cheat Sheet](http://www.rexegg.com/regex-quickstart.html) and [PCRE Regex Cheatsheet](https://www.debuggex.com/cheatsheet/regex/pcre).
341
+
342
+
Please wait a few moments until the `go-demo` service is running. You can see the status of the service by executing `docker service ps go-demo`.
343
+
344
+
Once the `go-demo` service is up and running, we can confirm that the proxy was indeed configured correctly.
345
+
346
+
```bash
347
+
curl -i $(docker-machine ip node-1)/something/hello
348
+
```
349
+
350
+
The output is as follows.
351
+
352
+
```
353
+
HTTP/1.1 200 OK
354
+
Date: Sun, 11 Dec 2016 18:43:21 GMT
355
+
Content-Length: 14
356
+
Content-Type: text/plain; charset=utf-8
357
+
358
+
hello, world!
359
+
```
360
+
361
+
We sent a request to `/something/hello`. The proxy accepted the request, rewrote the path to `/demo/hello`, and forwarded it to the `go-demo` service.
362
+
363
+
Let's remove the `go-demo` service before we proceed with *authentication*.
364
+
365
+
```bash
366
+
docker service rm go-demo
367
+
```
368
+
317
369
## Basic Authentication
318
370
319
371
*Docker Flow: Proxy* can provide basic authentication that can be applied on two levels. We can configure the proxy to protect all or only a selected service.
320
372
321
373
### Global Authentication
322
374
375
+
We'll start by recreating the `go-demo` service we removed earlier.
376
+
377
+
```bash
378
+
docker service create --name go-demo \
379
+
-e DB=go-demo-db \
380
+
--network go-demo \
381
+
--network proxy \
382
+
--label com.df.notify=true \
383
+
--label com.df.distribute=true \
384
+
--label com.df.servicePath=/demo \
385
+
--label com.df.port=8080 \
386
+
--replicas 3 \
387
+
vfarcic/go-demo
388
+
```
389
+
323
390
To configure the proxy to protect all the services, we need to specify the environment variable `USERS`.
324
391
325
392
As an example, we'll update the `proxy` service by adding the environment variable `USERS`.
0 commit comments