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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

haproxy.cfg 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 the
  23. # host's IPV6_V6ONLY sysctl. v6only on the v6 bind avoids the
  24. # "address in use" overlap on dual-stack hosts.
  25. bind 0.0.0.0:80
  26. bind [::]:80 v6only
  27. mode http
  28. # Let Caddy answer ACME HTTP-01 challenges for Let's Encrypt.
  29. acl is_acme path_beg /.well-known/acme-challenge/
  30. use_backend web_acme if is_acme
  31. http-request redirect scheme https code 301
  32. # --- TLS :443 — SNI-based routing -------------------------------------------
  33. frontend tls
  34. bind 0.0.0.0:443
  35. bind [::]:443 v6only
  36. tcp-request inspect-delay 5s
  37. tcp-request content accept if { req_ssl_hello_type 1 }
  38. # Route Telegram clients to mtg. The domain is read from the $DOMAIN
  39. # environment variable (forwarded by docker-compose), so it stays in
  40. # sync with Caddy and there is no per-deploy edit to this file.
  41. use_backend mtg if { req_ssl_sni -i "${DOMAIN}" }
  42. default_backend web
  43. # Backends reach mtg and web on host loopback — they publish to 127.0.0.1
  44. # (see docker-compose.yml), and HAProxy runs in the host netns
  45. # (network_mode: host). PROXY v2 still carries the real client address
  46. # (v4 or v6) end-to-end, independent of the loopback transport.
  47. backend mtg
  48. # send-proxy-v2 prepends a PROXY protocol v2 header so mtg sees the
  49. # real client IP instead of HAProxy's. mtg must have
  50. # `proxy-protocol-listener = true` in its config.
  51. server mtg 127.0.0.1:3128 send-proxy-v2
  52. backend web
  53. # send-proxy-v2 prepends a PROXY protocol v2 header so Caddy logs the
  54. # real client IP instead of HAProxy's. Caddy must enable the
  55. # proxy_protocol listener wrapper on :8443 (see Caddyfile).
  56. server web 127.0.0.1:8443 send-proxy-v2
  57. backend web_acme
  58. mode http
  59. server web 127.0.0.1:8080