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
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

haproxy.cfg 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.
  34. # Replace "example.com" with the domain from your mtg secret.
  35. use_backend mtg if { req_ssl_sni -i example.com }
  36. default_backend web
  37. backend mtg
  38. # send-proxy-v2 prepends a PROXY protocol v2 header so mtg sees the
  39. # real client IP instead of HAProxy's. mtg must have
  40. # `proxy-protocol-listener = true` in its config.
  41. server mtg mtg:3128 send-proxy-v2
  42. backend web
  43. # send-proxy-v2 prepends a PROXY protocol v2 header so Caddy logs the
  44. # real client IP instead of HAProxy's. Caddy must enable the
  45. # proxy_protocol listener wrapper on :8443 (see Caddyfile).
  46. server web web:8443 send-proxy-v2
  47. backend web_acme
  48. mode http
  49. server web web:80