|
1 | 1 | # Use dfdaemon as an HTTP proxy |
2 | 2 |
|
3 | | -Dfdaemon can be used as an HTTP proxy to speed up image pulling from any registry |
4 | | -as well as general HTTP downloads. |
| 3 | +## Prerequisites |
5 | 4 |
|
6 | | -Please first ensure that you know how to install and run [supernode](install_server.md) |
7 | | -and [dfdaemon](install_client.md). |
| 5 | +You need to first install and configure [supernode](install_server.md) and [dfdaemon](install_client.md). |
8 | 6 |
|
9 | | -**HTTPS support is currently very limited. All HTTPS request will be tunneled |
10 | | -directly, without dfget.** |
| 7 | +## Proxy Configuration |
11 | 8 |
|
12 | | -## Proxy rule configuration |
13 | | - |
14 | | -Proxy rules are configured in `/etc/dragonfly/dfdaemon.yml`. For performance |
15 | | -reason, dfdaemon will handle a request with the the first matching rule. |
| 9 | +Proxy rules are configured in `/etc/dragonfly/dfdaemon.yml`. |
16 | 10 |
|
17 | 11 | ```yaml |
| 12 | +# Requests that match the regular expressions will be proxied with dfget, |
| 13 | +# otherwise they'll be proxied directly. Requests will be handled by the first |
| 14 | +# matching rule. |
18 | 15 | proxies: |
19 | | -# proxy requests directly, without dfget |
| 16 | + # proxy all http image layer download requests with dfget |
| 17 | +- regx: blobs/sha256:.* |
| 18 | + # proxy requests directly, without dfget |
20 | 19 | - regx: no-proxy-reg |
21 | 20 | direct: true |
22 | | -# proxy all http image layer download requests with dfget |
23 | | -- regx: blobs/sha256:.* |
24 | | -# change http requests to some-registry to https, and proxy them with dfget |
| 21 | + # change http requests to some-registry to https, and proxy them with dfget |
25 | 22 | - regx: some-registry/ |
26 | 23 | use_https: true |
27 | | -``` |
28 | | -
|
29 | | -## Download images |
30 | | -
|
31 | | -Add the following content to `/etc/dragonfly/dfdaemon.yml`. |
32 | | - |
33 | | -```yaml |
34 | | -proxies: |
35 | | -# proxy all http image layer download requests with dfget |
36 | | -- regx: blobs/sha256:.* |
37 | | -``` |
38 | | - |
39 | | -Set HTTP_PROXY for docker daemon in `/etc/systemd/system/docker.service.d/http-proxy.conf`. |
40 | | -`65001` is the default proxy port for dfdaemon. |
41 | | - |
42 | | -``` |
43 | | -[Service] |
44 | | -Environment="HTTP_PROXY=http://127.0.0.1:65001" |
45 | | -``` |
46 | 24 |
|
47 | | -Set your registry as insecure in `/etc/docker/daemon.json` |
48 | | -
|
49 | | -```json |
50 | | -{ |
51 | | - "insecure-registries": [ "your.registry" ] |
52 | | -} |
| 25 | +# If an https request's host matches any of the hijacking rules, dfdaemon will |
| 26 | +# decrypt the request with given key pair and proxy it with the proxy rules. |
| 27 | +hijack_https: |
| 28 | + cert: df.crt |
| 29 | + key: df.key |
| 30 | + hosts: |
| 31 | + # match hosts by regular expressions. certificate will be validated normally |
| 32 | + - regx: host-1 |
| 33 | + # ignore certificate errors |
| 34 | + - regx: host-2 |
| 35 | + insecure: true |
| 36 | + # use the given certificate for validation |
| 37 | + - regx: host-3 |
| 38 | + certs: ["server.crt"] |
53 | 39 | ``` |
54 | 40 |
|
55 | | -Start dfdaemon and restart docker daemon. |
| 41 | +## Usage |
56 | 42 |
|
57 | | -``` |
58 | | -systemctl restart docker |
59 | | -``` |
| 43 | +You can use dfdaemon like any other HTTP proxy. For example on linux and |
| 44 | +macOS, you can use the `HTTP_PROXY` or `HTTPS_PROXY` environment variables. |
60 | 45 |
|
61 | | -Pull an image to see if it works. For registries that are not configured |
62 | | -insecure, you can still pull image from it, but dfdaemon will not be able to |
63 | | -speed up your downloads with dfget. |
| 46 | +## Get the Certificate of Your Server |
64 | 47 |
|
65 | 48 | ``` |
66 | | -docker pull nginx |
67 | | -docker pull your.registry/team/repo:tag |
| 49 | +openssl x509 -in <(openssl s_client -showcerts -servername xxx -connect xxx:443 -prexit 2>/dev/null) |
68 | 50 | ``` |
69 | | - |
70 | | -Then you can [check if your image is downloaded with dfget](../../FAQ.md#how-to-check-if-block-piece-is-distributed-among-dfgets-nodes). |
71 | | - |
72 | | -## Download files |
73 | | - |
74 | | -You can simply use `HTTP_PROXY` environment variable to let dfdaemon download |
75 | | -requests that match the proxy rules. This works for any program that |
76 | | -respects the `HTTP_PROXY` environment variable. |
77 | | - |
78 | | -``` |
79 | | -HTTP_PROXY=http://127.0.0.1:65001 curl http://github.com |
80 | | -``` |
81 | | - |
82 | | -HTTPS requests and requests that are not matched, will be proxied directly, |
83 | | -and dragonfly is not able to speed up them. |
84 | | - |
0 commit comments