|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+# SNI-routing deployment for mtg
|
|
|
2
|
+
|
|
|
3
|
+A turnkey `docker compose` setup that puts an SNI-aware TCP router
|
|
|
4
|
+(HAProxy) in front of mtg **and** a real web server (Caddy with
|
|
|
5
|
+automatic HTTPS).
|
|
|
6
|
+
|
|
|
7
|
+## Why
|
|
|
8
|
+
|
|
|
9
|
+Modern DPI systems actively probe suspected proxies. If the server
|
|
|
10
|
+closes the connection or returns something unexpected, the IP gets
|
|
|
11
|
+flagged. With this setup:
|
|
|
12
|
+
|
|
|
13
|
+- **Telegram clients** connect to port 443, HAProxy sees the configured
|
|
|
14
|
+ SNI and routes them to mtg (FakeTLS).
|
|
|
15
|
+- **Everything else** (browsers, DPI probes, scanners) is routed to
|
|
|
16
|
+ Caddy, which responds with a real Let's Encrypt certificate and serves
|
|
|
17
|
+ genuine web content.
|
|
|
18
|
+
|
|
|
19
|
+Because your domain's DNS points to this server, the SNI/IP match is
|
|
|
20
|
+natural and passive DPI has nothing to flag.
|
|
|
21
|
+
|
|
|
22
|
+## Quick start
|
|
|
23
|
+
|
|
|
24
|
+```bash
|
|
|
25
|
+# 1. Point your domain's DNS A/AAAA record to this server's IP.
|
|
|
26
|
+
|
|
|
27
|
+# 2. Generate an mtg secret:
|
|
|
28
|
+docker run --rm nineseconds/mtg:2 generate-secret --hex YOUR_DOMAIN
|
|
|
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
|
|
|
34
|
+
|
|
|
35
|
+# 4. (Optional) put your site content into www/
|
|
|
36
|
+
|
|
|
37
|
+# 5. Start:
|
|
|
38
|
+docker compose up -d
|
|
|
39
|
+
|
|
|
40
|
+# 6. Verify:
|
|
|
41
|
+# - Open https://YOUR_DOMAIN in a browser → you should see the web page
|
|
|
42
|
+# - Configure Telegram with the proxy link from:
|
|
|
43
|
+docker compose exec mtg mtg access /config/config.toml
|
|
|
44
|
+```
|
|
|
45
|
+
|
|
|
46
|
+## Real client IPs (PROXY protocol)
|
|
|
47
|
+
|
|
|
48
|
+HAProxy forwards TCP connections to mtg and Caddy with a PROXY protocol
|
|
|
49
|
+v2 header so both backends see the real client IP instead of HAProxy's
|
|
|
50
|
+container address. The three pieces must stay in sync:
|
|
|
51
|
+
|
|
|
52
|
+- `haproxy.cfg` — `send-proxy-v2` on the `mtg` and `web` backend `server` lines
|
|
|
53
|
+- `mtg-config.toml` — `proxy-protocol-listener = true`
|
|
|
54
|
+- `Caddyfile` — `listener_wrappers { proxy_protocol { ... } tls }` on `:8443`
|
|
|
55
|
+
|
|
|
56
|
+If you disable one, disable all three, otherwise the backend will fail
|
|
|
57
|
+to parse the connection.
|
|
|
58
|
+
|
|
|
59
|
+## ACME (Let's Encrypt) notes
|
|
|
60
|
+
|
|
|
61
|
+HAProxy passes `/.well-known/acme-challenge/` requests on `:80` to
|
|
|
62
|
+Caddy so that HTTP-01 validation works out of the box. Make sure your
|
|
|
63
|
+domain's DNS A/AAAA record points to this server before starting.
|
|
|
64
|
+
|
|
|
65
|
+## Architecture
|
|
|
66
|
+
|
|
|
67
|
+```
|
|
|
68
|
+ ┌──────────────────┐
|
|
|
69
|
+ :443 ──────>│ HAProxy │
|
|
|
70
|
+ │ (TCP, SNI peek) │
|
|
|
71
|
+ └──┬───────────┬───┘
|
|
|
72
|
+ SNI match │ │ default
|
|
|
73
|
+ v v
|
|
|
74
|
+ ┌─────────┐ ┌─────────┐
|
|
|
75
|
+ │ mtg │ │ Caddy │
|
|
|
76
|
+ │ :3128 │ │ :8443 │
|
|
|
77
|
+ │ FakeTLS │ │ real TLS│
|
|
|
78
|
+ └─────────┘ └─────────┘
|
|
|
79
|
+```
|
|
|
80
|
+
|
|
|
81
|
+## Files
|
|
|
82
|
+
|
|
|
83
|
+| File | Purpose |
|
|
|
84
|
+|---|---|
|
|
|
85
|
+| `docker-compose.yml` | Service definitions |
|
|
|
86
|
+| `haproxy.cfg` | SNI routing rules — **edit the domain** |
|
|
|
87
|
+| `mtg-config.toml` | mtg proxy config — **paste your secret** |
|
|
|
88
|
+| `Caddyfile` | Web server config (auto-HTTPS) |
|
|
|
89
|
+| `www/` | Static site content served by Caddy |
|