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 символов.

example.config.toml 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. # This is an example of the configuration file for mtg. You actually can
  2. # run mtg with it. It starts a proxy on all interfaces with a secret
  3. # ee367a189aee18fa31c190054efd4a8e9573746f726167652e676f6f676c65617069732e636f6d
  4. #
  5. # It has all possible options with default values. So, a real world
  6. # configuration file should contain only those options you are going to
  7. # use. You do not need to enumerate all of them. In other words, each
  8. # option here has a default value. If you comment a key-value pair, it
  9. # should not make any effect.
  10. #
  11. # stats is the only exception.
  12. # Debug starts application in debug mode. It starts to be quite verbose
  13. # in output. Actually, the idea is that you run it in debug mode only if
  14. # you have any issue.
  15. debug = true
  16. # A secret. Please remember that mtg supports only FakeTLS mode, legacy
  17. # simple and secured mode are prohibited. For you it means that secret
  18. # should either be base64-encoded or starts with ee.
  19. secret = "ee367a189aee18fa31c190054efd4a8e9573746f726167652e676f6f676c65617069732e636f6d"
  20. # Host:port pair to run proxy on.
  21. bind-to = "0.0.0.0:3128"
  22. # This defines what types of traffic mtg listens to. If you are not sure,
  23. # then definitely keep it disable. Enable it only and only if incoming traffic
  24. # is coming from some sort of load-balancer like HAProxy or ELB.
  25. # https://www.haproxy.org/download/2.3/doc/proxy-protocol.txt
  26. #
  27. # mtg uses a library that supports v1 and v2 versions of ProxyProtocol.
  28. # default value is false.
  29. # proxy-protocol-listener = false
  30. # Defines how many concurrent connections are allowed to this proxy.
  31. # All other incoming connections are going to be dropped.
  32. concurrency = 8192
  33. # Sometimes you want to enforce mtg to use some types of
  34. # IP connectivity to Telegram. We have 4 modes:
  35. # - prefer-ipv6:
  36. # We can use both ipv4 and ipv6 but ipv6 has a preference
  37. # - prefer-ipv4:
  38. # We can use both ipv4 and ipv6 but ipv4 has a preference
  39. # - only-ipv6:
  40. # Only ipv6 connectivity is used
  41. # - only-ipv4:
  42. # Only ipv4 connectivity is used
  43. prefer-ip = "prefer-ipv6"
  44. # Public IP addresses of this server. Used by 'mtg access' to generate
  45. # proxy links and by 'mtg doctor' to validate SNI-DNS match.
  46. # If not set, mtg tries to detect them automatically via ifconfig.co.
  47. # Set these if ifconfig.co is unreachable from your server.
  48. # public-ipv4 = "1.2.3.4"
  49. # public-ipv6 = "2001:db8::1"
  50. # If this setting is set, then mtg will try to get proxy updates from Telegram
  51. # Usually this is completely fine to have it disabled, because mtg has a list
  52. # of some core proxies hardcoded.
  53. auto-update = false
  54. # FakeTLS uses domain fronting protection. So it needs to know a port to
  55. # access.
  56. #
  57. # Deprecated: use [domain-fronting] configuration block. If relevant option
  58. # is defined there, this one would be ignored.
  59. # domain-fronting-port = 443
  60. # By default, mtg resolves the fronting hostname (from the secret) via DNS
  61. # to establish a TCP connection. If DNS resolution of that hostname is blocked,
  62. # you can specify an IP address to connect to directly. The hostname is still
  63. # used for SNI in the TLS handshake.
  64. #
  65. # default value is not set (DNS resolution is used).
  66. #
  67. # Deprecated: use [domain-fronting] configuration block. If relevant option
  68. # is defined there, this one would be ignored.
  69. # domain-fronting-ip = "10.0.0.10"
  70. # This makes a communication between both fronting website and mtg to use
  71. # proxy protocol.
  72. #
  73. # Deprecated: use [domain-fronting] configuration block. If relevant option
  74. # is defined there, this one would be ignored.
  75. # domain-fronting-proxy-protocol = false
  76. # FakeTLS can compare timestamps to prevent probes. Each message has
  77. # encrypted timestamp. So, mtg can compare this timestamp and decide if
  78. # we need to proceed with connection or not.
  79. #
  80. # Sometimes time can be skewed so we accept all messages within a
  81. # time range of this parameter.
  82. tolerate-time-skewness = "5s"
  83. # Telegram has a concept of DC. You can think about DC as a number of a cluster
  84. # with a certain purpose. Some clusters serve media, some - messages, some rule
  85. # channels and so on. But sometimes unknown DC number is requested by client.
  86. # It could be a bug or some global reconfiguration of the Telegram.
  87. #
  88. # By default, proxy rejects such requests. But it is also possible to fallback
  89. # this request to any DC. Telegram works in a way that any DC is able to serve
  90. # any request but sacrificing a latency.
  91. #
  92. # If this setting is disabled (default), mtg will reject a connection.
  93. # Otherwise, chose a new DC.
  94. allow-fallback-on-unknown-dc = false
  95. # This section is relevant to communication with fronting domain. Usually
  96. # you do not need to setup anything here but there are plenty of cases, especially
  97. # if you put mtg behind load balancer, when some specific configuration is
  98. # required.
  99. [domain-fronting]
  100. # By default, mtg resolves the fronting hostname (from the secret) via DNS
  101. # to establish a TCP connection. If that resolution is blocked, or loops
  102. # back to this server (e.g. mtg sits behind an SNI router whose DNS points
  103. # at itself), override the destination here.
  104. #
  105. # Use `host` — accepts a hostname or a literal IP. Hostnames are resolved
  106. # at dial time, so a dual-stack DNS record can reach the right backend
  107. # address family for IPv4 or IPv6 clients.
  108. #
  109. # The hostname from the secret is still used for SNI in the TLS handshake.
  110. #
  111. # default value is not set (the secret's hostname is used).
  112. # host = "fronting-backend"
  113. # Deprecated: use `host`. If `ip` is set, mtg logs a warning at startup
  114. # and ignores the value (domain-fronting falls back to the secret's
  115. # hostname unless `host` is also set).
  116. # ip = "10.10.10.11"
  117. # FakeTLS uses domain fronting protection. So it needs to know a port to
  118. # access. Default value is 443
  119. # port = 443
  120. # This makes a communication between both fronting website and mtg to use
  121. # proxy protocol.
  122. # proxy-protocol = false
  123. # network defines different network-related settings
  124. [network]
  125. # please be aware that mtg needs to do some external requests. For
  126. # example, if you do not pass public ips, it will request your public ip
  127. # address from some external service.
  128. #
  129. # As for 2.0, if you set a public-ip on your own, mtg won't issue any
  130. # network requests except of those required for Telegram.
  131. #
  132. # so, in order of doing them, it needs to do DNS lookup. mtg ignores DNS
  133. # resolver of the operating system and uses DOH instead. This is a host
  134. # it has to access.
  135. #
  136. # By default we use Cloudflare.
  137. #
  138. # DEPRECATED option:
  139. # If dns option is specified, it will be used instead. No default is defined
  140. # anymore. But if you set this option, this is literally the same providing
  141. # https:// URL to `dns`.
  142. #
  143. # In other words:
  144. #
  145. # doh-ip = "1.1.1.1"
  146. #
  147. # is literally the same as
  148. #
  149. # dns = "https://1.1.1.1"
  150. # doh-ip = "1.1.1.1"
  151. # Starting from mtg v2.1.12 we have changed a configuration for DNS. Now it
  152. # supports DNS-over-HTTPS, DNS-over-TLS, custom UDP resolver and system
  153. # resolver.
  154. #
  155. # Here is how to define DNS-over-HTTPS:
  156. # - https://1.1.1.1
  157. # - https://1.1.1.1/dns-query
  158. # - https://cloudflare-dns.com/dns-query
  159. # - https://cloudflare-dns.com
  160. #
  161. # Here is how to define DNS-over-TLS:
  162. # - tls://1.1.1.1
  163. # - tls://cloudflare-dns.com
  164. #
  165. # Here is how to define a custom UDP resolver (we support only IPs here)
  166. # - 1.1.1.1
  167. # - udp://1.1.1.1
  168. #
  169. # If you set it to empty string, default resolver will be used.
  170. # But please comment out doh-ip
  171. dns = "https://1.1.1.1"
  172. # mtg can work via proxies (for now, we support only socks5). Proxy
  173. # configuration is done via list. So, you can specify many proxies
  174. # there.
  175. #
  176. # Actually, if you supply an empty list, then no proxies are going to be
  177. # used. If you supply a single proxy, then mtg will use it exclusively.
  178. # If you supply >= 2, then mtg will load balance between them.
  179. #
  180. # If you add an empty string here, this is an equivalent of 'plain network',
  181. # with no proxy usage.
  182. #
  183. # Proxy configuration is done via ordinary URI schema:
  184. #
  185. # socks5://user:password@host:port
  186. #
  187. # Only socks5 proxy is used. user/password is optional. As you can
  188. # see, you can specify some parameters in GET query. These parameters
  189. # configure circuit breaker.
  190. proxies = [
  191. # "socks5://user:password@host:port"
  192. ]
  193. # network timeouts define different settings for timeouts. tcp timeout
  194. # define a global timeout on establishing of network connections. idle
  195. # means a timeout on pumping data between sockset when nothing is
  196. # happening.
  197. [network.timeout]
  198. tcp = "5s"
  199. http = "10s"
  200. idle = "5m"
  201. handshake = "10s"
  202. # TCP_NOTSENT_LOWAT (bytes) caps the amount of *unsent* data that the
  203. # kernel buffers per outbound socket. When the not-yet-sent backlog drops
  204. # below this threshold the socket becomes writable again, which applies
  205. # back-pressure to mtg's relay loop instead of letting kernel buffers
  206. # bloat. This reduces per-connection memory and bufferbloat, but on
  207. # high-BDP links (fast pipe × high RTT) it can cap single-flow upload
  208. # throughput at roughly value / RTT.
  209. #
  210. # Default is 128kib (good for interactive latency). If uploads through
  211. # the proxy feel slow on a fast link, raise this to 1mib–4mib. Suffixes
  212. # follow the same scheme as anti-replay max-size (kib, mib, gib).
  213. # Only applies to Linux and Darwin; ignored on other platforms.
  214. # tcp-not-sent-lowat = "128kib"
  215. # this defines a configuration for TCP keep alives. Default values are taken
  216. # from Golang default behavior.
  217. [network.keep-alive]
  218. disabled = false
  219. # idle means a time period after which we start sending TCP Keep Alive probes
  220. idle = "15s"
  221. # interval is a period between 2 consecutive probes
  222. interval = "15s"
  223. # if we miss that many probes, a connection will be considered as a dead one.
  224. count = 9
  225. # mtg has to mimic real websites. It does not mean domain fronting, it also
  226. # means that traffic characteristics should be similar to real world traffic.
  227. # websites and applications behave differently, their traffic patterns are also
  228. # different. Applications do bursts of RPC-style messages (or JSON communication,
  229. # does not really matter), while websites pump heavy content in HTTP2 streams
  230. #
  231. # It means that statistically there is a different between traffic shape:
  232. # delays between packets are also different.
  233. # In order to avoid censorship detection based on these patterns, there is a
  234. # mtg subsystem called "Doppelganger" that aims to mimic website statistics
  235. # as close as it could.
  236. #
  237. # Delays between TLS packets are not constant. There are many factors
  238. # that come in play. Application should generate some response, it could
  239. # send some headers first and stream content with chunked encoding. So
  240. # some first packets could come as soon as possible, with some delays
  241. # after first ones. Such phenomenon is described by different statistic
  242. # distribution. There are 2 distribution that describe it: lognormal
  243. # distribution and Weibul distribution. Lognormal is all about steady streams
  244. # of heavy content like a video. Weibul is great about short bursts like
  245. # user who requested a static page an a couple of images.
  246. [defense.doppelganger]
  247. # This is a list of URLs that would be crawled by mtg to approximate delay
  248. # statistics. They MUST be HTTPS urls.
  249. #
  250. # You can come to the website and collect different URLs, with light and
  251. # heavy content. We recommend to search for CDNs.
  252. urls = [
  253. # "https://st-ok.cdn-vk.ru/res/react/vendor/clsx-2.1.1-amd.js"
  254. ]
  255. # A collection is done in raids. Each raid makes this number of requests to
  256. # each URL in this list. Do not use a huge number, 10 is probably ok.
  257. repeats-per-raid = 10
  258. # This is a duration between each raid. It makes no sense to have a small number
  259. # here as you would start to make a noticeable activity. Usually traffic patterns
  260. # do not change a lot, so do not expect different results if you request
  261. # each 10 minutes.
  262. raid-each = "6h"
  263. # This enables dynamic tls record sizing.
  264. #
  265. # Some modern stacks and platforms start to use the technique that is called
  266. # DRS. They start with small TLS packets and ramp up eventually. First packets
  267. # are usually about MTU size, after that we get 4k and eventually max size.
  268. # This is done with a good intention: to minimize a time to the first byte,
  269. # so application could start doing something with the data right after first
  270. # RTT.
  271. #
  272. # Apparently, about 90% of application do not employ this technique, they use
  273. # max size always: nginx, apache, java stuff. But Golang tools, angie and
  274. # some specific patches activate this technique.
  275. #
  276. # In order to mimic a real website we need to know something about software
  277. # it uses. Usually nobody cares: openssl does 16384, Python does it, nginx
  278. # does it. So this setting is disabled by default.
  279. #
  280. # https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency/
  281. # https://aws.github.io/s2n-tls/usage-guide/ch08-record-sizes.html
  282. # https://github.com/cloudflare/sslconfig/blob/master/patches/nginx__dynamic_tls_records.patch
  283. drs = false
  284. # Some countries do active probing on Telegram connections. This technique
  285. # allows to protect from such effort.
  286. #
  287. # mtg has a cache of some connection fingerprints. Actually, first bytes
  288. # of each connection. So, it stores them in some in-memory LRU+TTL cache.
  289. # You can configure this cache here.
  290. [defense.anti-replay]
  291. # You can enable/disable this feature.
  292. enabled = true
  293. # max size of such a cache. Please be aware that this number is
  294. # approximate we try hard to store data quite dense but it is possible
  295. # that we can go over this limit for 10-20% under some conditions and
  296. # architectures.
  297. max-size = "1mib"
  298. # we use stable bloom filters for anti-replay cache. This helps
  299. # to maintain a desired error ratio.
  300. error-rate = 0.001
  301. # You can protect proxies by using different blocklists. If client has
  302. # ip from the given range, we do not try to do a proper handshake. We
  303. # actually route it to fronting domain. So, this client will never ever
  304. # have a chance to use mtg to access Telegram.
  305. #
  306. # Please remember that blocklists are initialized in async way. So,
  307. # when you start a proxy, blocklists are empty, they are populated and
  308. # processed in backgrounds. An error in any URL is ignored.
  309. [defense.blocklist]
  310. # You can enable/disable this feature.
  311. enabled = true
  312. # This is a limiter for concurrency. In order to protect website
  313. # from overloading, we download files in this number of threads.
  314. download-concurrency = 2
  315. # A list of URLs in FireHOL format (https://iplists.firehol.org/)
  316. # You can provider links here (starts with https:// or http://) or
  317. # path to a local file, but in this case it should be absolute.
  318. #
  319. # NOTE: the default list below (firehol_level1.netset) includes bogon
  320. # networks, and therefore RFC1918 ranges as well (10.0.0.0/8,
  321. # 172.16.0.0/12, 192.168.0.0/16). If you run mtg on a home/LAN network
  322. # and connect from a client on the same LAN, that client will be
  323. # rejected with "ip was blacklisted" and the connection dropped (TCP
  324. # close, no response). If you see this, you can either disable this section
  325. # (enabled = false), replace firehol_level1 with a narrower list that
  326. # does not include bogons (e.g. firehol_abusers_1d), or connect via
  327. # a public IP/domain with hairpin NAT on your router. See README for
  328. # details.
  329. urls = [
  330. "https://iplists.firehol.org/files/firehol_level1.netset",
  331. # "/local.file"
  332. ]
  333. # How often do we need to update a blocklist set.
  334. update-each = "24h"
  335. # Allowlist is an opposite to a blocklist. Only those IPs that are coming from
  336. # subnets defined in these lists are allowed. All others will be rejected.
  337. #
  338. # If this feature is disabled, then there won't be any check performed by this
  339. # validator. It is possible to combine both blocklist and whitelist.
  340. [defense.allowlist]
  341. # You can enable/disable this feature.
  342. enabled = false
  343. # This is a limiter for concurrency. In order to protect website
  344. # from overloading, we download files in this number of threads.
  345. download-concurrency = 2
  346. # A list of URLs in FireHOL format (https://iplists.firehol.org/)
  347. # You can provider links here (starts with https:// or http://) or
  348. # path to a local file, but in this case it should be absolute.
  349. urls = [
  350. # "https://iplists.firehol.org/files/firehol_level1.netset",
  351. # "/local.file"
  352. ]
  353. update-each = "24h"
  354. # statsd statistics integration.
  355. [stats.statsd]
  356. # enabled/disabled
  357. enabled = false
  358. # host:port for UDP endpoint of statsd
  359. address = "127.0.0.1:8888"
  360. # prefix of metric for statsd
  361. metric-prefix = "mtg"
  362. # tag format to use
  363. # supported values are 'datadog', 'influxdb' and 'graphite'
  364. # default format is graphite.
  365. tag-format = "datadog"
  366. # prometheus metrics integration.
  367. [stats.prometheus]
  368. # enabled/disabled
  369. enabled = true
  370. # host:port where to start http server for endpoint
  371. bind-to = "127.0.0.1:3129"
  372. # prefix of http path
  373. http-path = "/"
  374. # prefix for metrics for prometheus
  375. metric-prefix = "mtg"