Alexey Dolotov 6 дней назад
Родитель
Сommit
29a134802a
Аккаунт пользователя с таким Email не найден

+ 4
- 5
contrib/sni-router/README.md Просмотреть файл

27
 # 2. Generate an mtg secret:
27
 # 2. Generate an mtg secret:
28
 docker run --rm nineseconds/mtg:2 generate-secret --hex YOUR_DOMAIN
28
 docker run --rm nineseconds/mtg:2 generate-secret --hex YOUR_DOMAIN
29
 
29
 
30
-# 3. Edit the config files:
31
-#    - mtg-config.toml  →  paste the secret
32
-#    - haproxy.cfg       →  replace "example.com" in the SNI ACL
33
-#    - .env or export    →  DOMAIN=your.domain
30
+# 3. Configure:
31
+#    - .env (or export)  →  DOMAIN=your.domain   # used by HAProxy + Caddy
32
+#    - mtg-config.toml   →  paste the secret
34
 
33
 
35
 # 4. (Optional) put your site content into www/
34
 # 4. (Optional) put your site content into www/
36
 
35
 
83
 | File | Purpose |
82
 | File | Purpose |
84
 |---|---|
83
 |---|---|
85
 | `docker-compose.yml` | Service definitions |
84
 | `docker-compose.yml` | Service definitions |
86
-| `haproxy.cfg` | SNI routing rules — **edit the domain** |
85
+| `haproxy.cfg` | SNI routing rules (reads `$DOMAIN` from the environment) |
87
 | `mtg-config.toml` | mtg proxy config — **paste your secret** |
86
 | `mtg-config.toml` | mtg proxy config — **paste your secret** |
88
 | `Caddyfile` | Web server config (auto-HTTPS) |
87
 | `Caddyfile` | Web server config (auto-HTTPS) |
89
 | `www/` | Static site content served by Caddy |
88
 | `www/` | Static site content served by Caddy |

+ 12
- 5
contrib/sni-router/docker-compose.yml Просмотреть файл

9
 # SNI/IP because the domain resolves to this server's IP.
9
 # SNI/IP because the domain resolves to this server's IP.
10
 #
10
 #
11
 # Quick start:
11
 # Quick start:
12
-#   1. Set YOUR_DOMAIN below (and in mtg-config.toml)
13
-#   2. docker compose up -d
14
-#   3. mtg generate-secret YOUR_DOMAIN   -> put it in mtg-config.toml
15
-#   4. docker compose restart mtg
12
+#   1. Set DOMAIN in a .env file next to this one (or export it)
13
+#   2. mtg generate-secret YOUR_DOMAIN   -> paste into mtg-config.toml
14
+#   3. docker compose up -d
15
+#
16
+# DOMAIN is forwarded to both Caddy (TLS cert) and HAProxy (SNI ACL),
17
+# so the SNI/cert/secret all line up from a single source.
16
 #
18
 #
17
 # See BEST_PRACTICES.md and the project wiki for background.
19
 # See BEST_PRACTICES.md and the project wiki for background.
18
 
20
 
21
+x-domain-env: &domain-env
22
+  DOMAIN: ${DOMAIN:-example.com}
23
+
19
 services:
24
 services:
20
   haproxy:
25
   haproxy:
21
     image: haproxy:lts-alpine
26
     image: haproxy:lts-alpine
24
       - "80:80"
29
       - "80:80"
25
     volumes:
30
     volumes:
26
       - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro,Z
31
       - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro,Z
32
+    environment:
33
+      <<: *domain-env
27
     depends_on:
34
     depends_on:
28
       - mtg
35
       - mtg
29
       - web
36
       - web
51
       - "80"
58
       - "80"
52
       - "8443"
59
       - "8443"
53
     environment:
60
     environment:
54
-      DOMAIN: ${DOMAIN:-example.com}
61
+      <<: *domain-env
55
     restart: unless-stopped
62
     restart: unless-stopped
56
 
63
 
57
 volumes:
64
 volumes:

+ 4
- 3
contrib/sni-router/haproxy.cfg Просмотреть файл

39
     tcp-request inspect-delay 5s
39
     tcp-request inspect-delay 5s
40
     tcp-request content accept if { req_ssl_hello_type 1 }
40
     tcp-request content accept if { req_ssl_hello_type 1 }
41
 
41
 
42
-    # Route Telegram clients to mtg.
43
-    # Replace "example.com" with the domain from your mtg secret.
44
-    use_backend mtg if { req_ssl_sni -i example.com }
42
+    # Route Telegram clients to mtg.  The domain is read from the $DOMAIN
43
+    # environment variable (forwarded by docker-compose), so it stays in
44
+    # sync with Caddy and there is no per-deploy edit to this file.
45
+    use_backend mtg if { req_ssl_sni -i "${DOMAIN}" }
45
 
46
 
46
     default_backend web
47
     default_backend web
47
 
48
 

+ 3
- 3
contrib/sni-router/mtg-config.toml Просмотреть файл

1
 # Minimal mtg configuration for the SNI-router setup.
1
 # Minimal mtg configuration for the SNI-router setup.
2
 #
2
 #
3
-# 1. Generate a secret:  mtg generate-secret --hex example.com
4
-# 2. Paste it below.
5
-# 3. Replace example.com with your actual domain everywhere.
3
+# 1. Generate a secret:  mtg generate-secret --hex <your.domain>
4
+# 2. Paste it into the `secret` field below.
5
+# 3. Set DOMAIN=<your.domain> in .env (HAProxy + Caddy pick it up).
6
 
6
 
7
 secret = "PASTE_YOUR_SECRET_HERE"
7
 secret = "PASTE_YOUR_SECRET_HERE"
8
 bind-to = "0.0.0.0:3128"
8
 bind-to = "0.0.0.0:3128"

Загрузка…
Отмена
Сохранить