Pārlūkot izejas kodu

contrib/sni-router: read $DOMAIN from env in haproxy.cfg

Closes #501.

Before: the SNI hostname had to be edited in haproxy.cfg, plus
DOMAIN had to be set in .env for Caddy.  Two places to keep in sync.

After: DOMAIN is the single source — set it once in .env (or export),
docker-compose forwards it into both haproxy and caddy containers,
and HAProxy interpolates ${DOMAIN} into the SNI ACL at startup.

mtg-config.toml's secret still embeds the domain in its bytes
(generated once with `mtg generate-secret <domain>`), so that one
remains a one-time edit at install — the README is updated to reflect
this.

HAProxy has supported environment-variable substitution in config
strings since 1.6.
pull/502/head
Alexey Dolotov 1 nedēļu atpakaļ
vecāks
revīzija
1606afe3b1

+ 4
- 5
contrib/sni-router/README.md Parādīt failu

@@ -27,10 +27,9 @@ natural and passive DPI has nothing to flag.
27 27
 # 2. Generate an mtg secret:
28 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 34
 # 4. (Optional) put your site content into www/
36 35
 
@@ -83,7 +82,7 @@ domain's DNS A/AAAA record points to this server before starting.
83 82
 | File | Purpose |
84 83
 |---|---|
85 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 86
 | `mtg-config.toml` | mtg proxy config — **paste your secret** |
88 87
 | `Caddyfile` | Web server config (auto-HTTPS) |
89 88
 | `www/` | Static site content served by Caddy |

+ 8
- 4
contrib/sni-router/docker-compose.yml Parādīt failu

@@ -9,10 +9,12 @@
9 9
 # SNI/IP because the domain resolves to this server's IP.
10 10
 #
11 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 19
 # See BEST_PRACTICES.md and the project wiki for background.
18 20
 
@@ -24,6 +26,8 @@ services:
24 26
       - "80:80"
25 27
     volumes:
26 28
       - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro,Z
29
+    environment:
30
+      DOMAIN: ${DOMAIN:-example.com}
27 31
     depends_on:
28 32
       - mtg
29 33
       - web

+ 4
- 3
contrib/sni-router/haproxy.cfg Parādīt failu

@@ -39,9 +39,10 @@ frontend tls
39 39
     tcp-request inspect-delay 5s
40 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 47
     default_backend web
47 48
 

Notiek ielāde…
Atcelt
Saglabāt