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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

haproxy.cfg 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. bind *:80
  23. mode http
  24. # Let Caddy answer ACME HTTP-01 challenges for Let's Encrypt.
  25. acl is_acme path_beg /.well-known/acme-challenge/
  26. use_backend web_acme if is_acme
  27. http-request redirect scheme https code 301
  28. # --- TLS :443 — SNI-based routing -------------------------------------------
  29. frontend tls
  30. bind *:443
  31. tcp-request inspect-delay 5s
  32. tcp-request content accept if { req_ssl_hello_type 1 }
  33. # Route Telegram clients to mtg. The domain is read from the $DOMAIN
  34. # environment variable (forwarded by docker-compose), so it stays in
  35. # sync with Caddy and there is no per-deploy edit to this file.
  36. use_backend mtg if { req_ssl_sni -i "${DOMAIN}" }
  37. default_backend web
  38. backend mtg
  39. # send-proxy-v2 prepends a PROXY protocol v2 header so mtg sees the
  40. # real client IP instead of HAProxy's. mtg must have
  41. # `proxy-protocol-listener = true` in its config.
  42. server mtg mtg:3128 send-proxy-v2
  43. backend web
  44. # send-proxy-v2 prepends a PROXY protocol v2 header so Caddy logs the
  45. # real client IP instead of HAProxy's. Caddy must enable the
  46. # proxy_protocol listener wrapper on :8443 (see Caddyfile).
  47. server web web:8443 send-proxy-v2
  48. backend web_acme
  49. mode http
  50. server web web:80