Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

haproxy.cfg 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # HAProxy SNI router — Layer 4 (TCP mode)
  2. #
  3. # Inspects the SNI in the TLS ClientHello and routes traffic:
  4. # - SNI matching the mtg secret domain -> mtg (FakeTLS / MTProto)
  5. # - Everything else -> real web backend (Caddy)
  6. #
  7. # Because routing happens before TLS termination, each backend sees the
  8. # raw ClientHello and handles TLS itself. The real web backend therefore
  9. # presents a genuine certificate to any probe or browser.
  10. global
  11. log stdout format raw local0 info
  12. maxconn 4096
  13. defaults
  14. log global
  15. mode tcp
  16. option tcplog
  17. timeout connect 5s
  18. timeout client 60s
  19. timeout server 60s
  20. # --- HTTP :80 — ACME challenges + redirect -----------------------------------
  21. frontend http
  22. # Explicit v4 + v6 binds so IPv6 clients are accepted regardless of
  23. # the host's net.ipv6.bindv6only sysctl.
  24. bind :80,[::]:80
  25. mode http
  26. # Let Caddy answer ACME HTTP-01 challenges for Let's Encrypt.
  27. acl is_acme path_beg /.well-known/acme-challenge/
  28. use_backend web_acme if is_acme
  29. http-request redirect scheme https code 301
  30. # --- TLS :443 — SNI-based routing -------------------------------------------
  31. frontend tls
  32. bind :443,[::]:443
  33. tcp-request inspect-delay 5s
  34. tcp-request content accept if { req_ssl_hello_type 1 }
  35. # Route Telegram clients to mtg. The domain is read from the $DOMAIN
  36. # environment variable (forwarded by docker-compose), so it stays in
  37. # sync with Caddy and there is no per-deploy edit to this file.
  38. use_backend mtg if { req_ssl_sni -i "${DOMAIN}" }
  39. default_backend web
  40. # Backends reach mtg and web on host loopback — they publish to 127.0.0.1
  41. # (see docker-compose.yml), and HAProxy runs in the host netns
  42. # (network_mode: host). PROXY v2 still carries the real client address
  43. # (v4 or v6) end-to-end, independent of the loopback transport.
  44. backend mtg
  45. # send-proxy-v2 prepends a PROXY protocol v2 header so mtg sees the
  46. # real client IP instead of HAProxy's. mtg must have
  47. # `proxy-protocol-listener = true` in its config.
  48. server mtg 127.0.0.1:3128 send-proxy-v2
  49. backend web
  50. # send-proxy-v2 prepends a PROXY protocol v2 header so Caddy logs the
  51. # real client IP instead of HAProxy's. Caddy must enable the
  52. # proxy_protocol listener wrapper on :8443 (see Caddyfile).
  53. server web 127.0.0.1:8443 send-proxy-v2
  54. backend web_acme
  55. mode http
  56. server web 127.0.0.1:8080