We create MTProto server for proxy in telegram.

President

Professional
Messages
1,458
Reaction score
1,300
Points
113
With the release of MTProxy in Telegram, it became possible to monetize proxies, due to the promoted channel function. Now the creation of the MTProto server will be not just a charity gesture in support of Digital Resistance, but also a real way to promote your channel and start making money on advertising in Telegram.

There is also an alternative way for those who do not want to create an MTProto server. You can just buy fast private proxies in the Proxy-Sale.Com service (not advertising) and connect them in Telegram.

How to set up your own MTProto server for Telegram?
The Telegram team has published links to the repository with the code for creating a proxy server, and to the image for autodeploying the zero configuration of the MTProxy server. Docker container allows you to automatically deploy MTProto proxy server intended for Telegram.

Before the release of the official Docker image from Telegram, users managed to create various scripts to configure their own MTProxy. Let's take a quick look at what alternatives to the official Telegram solution exist.

Python: Supports sponsored channels supports IPv6; easy to install.
PHP: there are problems with Android clients (no messages sent); Telegram desktop clients work fine.
Java: JRE 8 or JDK 8 required (will not work on version 9 or higher).
C (Official version of MTProxy from Telegram): uses a lot of CPU resources; supports sponsored channels; works stably.

The official Docker image is the easiest, fastest and most efficient way to get your MTProto proxy server up and running. Automated container deployment and easy OS-level management allows you to configure a proxy server on any Linux system.

System requirements:
  • VDS / VPS server located in any country where Telegram is not blocked;
  • Linux OS: Ubuntu 14.04+, CentOS 6+, Debian 8+;
  • root access via SSH.

Create MTProto server
We only need a server with Docker installed and Internet access, and port 443 must be free. To start the proxy, all you need to do is run the command:
Code:
docker run -d -p443:443 --name=mtproto-proxy --restart=always -v proxy-config:/data telegrammessenger/proxy:latest

The container log is available by the command:
Code:
docker logs mtproto-proxy

It will contain the information that will be required to be inserted into the Telegram application when registering your proxy with the @MTProxyBot bot:
Code:
[+] Using the explicitly passed secret: '00baadf00d15abad1deaa515baadcafe'.[+] Saving it to /data/secret.[*] Final configuration:[*] Secret 1: 00baadf00d15abad1deaa515baadcafe# ваш текущий секретный ключ[*] tg:// link for secret 1 auto configuration: : tg://proxy?server=3.14.15.92&port=443&secret=00baadf00d15abad1deaa515baadcafe# ссылка для подключения[*] t.me link for secret 1: tg://proxy?server=3.14.15.92&port=443&secret=00baadf00d15abad1deaa515baadcafe[*] Tag: no tag # параметр для привязки promoted-канала[*] External IP: 3.14.15.92[*] Make sure to fix the links in case you run the proxy on a different port.

The IP and port parameters may be incorrect - check it out and correct if necessary. Also, be sure to correct the links if you decide to run the proxy server on a port other than 443.

Secret is a required configuration parameter: it will be created automatically when the container is started, and will persist across updates.

Register your MTProto proxy in Telegram
After your MTProxy server is running, open a dialogue with @MTProxybot in the messenger and register your proxy in Telegram to get access to usage and monetization statistics. @MTProxybot is the official bot for MTProxy owners. Procedure:
  1. Send the command / start .
  2. Then the / newproxy command is used to register a new MTProto.
  3. Send the address in the "host: port" format.

Configuring the MTProxy server
If you need to manually set the secret key (for example, when deploying multiple proxy servers with DNS load balancing), you can set the SECRET variable as a 16-byte hexadecimal number:
Code:
docker run -d -p443:443 -v proxy-config:/data -e SECRET=00baadf00d15abad1deaa51sbaadcafe telegrammessenger/proxy:latest

You must use lower case for characters. To generate the number, use one of the Linux commands:
Code:
$ tr -dc 'a-f0-9' < /dev/urandom | dd bs=1 count=32 2>/dev/null$ openssl rand -hex 16 # требуется openssl

MTProto supports setting several different keys for user groups at once, up to a maximum of 16 parameters. You can specify them explicitly in the SECRET variable as comma-separated hexadecimal strings:
Code:
docker run -d -p443:443 -v proxy-config:/data -e SECRET=935ddceb2f6bbbb78363b224099f75c8,2084c7e58d8213296a3206da70356c81 telegrammessenger/proxy:latest

Alternatively, you can let the container automatically create "secrets" using the SECRET_COUNT variable (you need to specify the number of generated rows).
Code:
docker run -d -p443:443 -v proxy-config:/data -e SECRET_COUNT=4 telegrammessenger/proxy:latest

MTProto server update
The Telegram team promised to make the minimum number of changes, but nevertheless, it is recommended to update the proxy server once a day. List of commands to update:

$ docker pull telegrammessenger/proxy # обновить образ$ docker stop mtproto-proxy # остановить контейнер$ docker rm mtproto-proxy # удалить контейнер$ docker run .... # создать из обновленного образа и запустить контейнер заново$ docker logs -f --tail=30 mtproto-proxy # посмотреть журнал контейнера

MTProxy statistics and performance
One workflow is designed to handle tens of thousands of client connections. For optimal performance, this number is artificially limited to 60,000 connections per CPU core. By default, two worker processes are started. If your proxy is designed for a large number of connections, be sure to set the WORKERS variable to increase the number of processes. However, you shouldn't run more proxy processes than there are cores in the processor.
Code:
docker run -d -p443:443 -v proxy-config:/data -e WORKERS=16 telegrammessenger/proxy:latest

You can view the main metrics of the MTProto proxy server on localhost:
Code:
http://localhost:2398/stats

If the proxy server is started with the parameter --net=host, to get statistics, run the command:
Code:
curl http://localhost:2398/stats

If the proxy is running with port forwarding, run another command:
Code:
$ docker exec mtproto-proxy curl http://localhost:2398/stats

Available metrics:
  • ready_targets - the number of main Telegram servers to which the proxy will try to connect.
  • active_targets is the number of main Telegram servers to which the proxy is actually connected. Must be equal to ready_targets.
  • total_special_connections - the number of incoming client connections to MTProxy.
  • total_max_special_connections - The upper limit for incoming connections to MTProxy. Equal to 60,000 times the number of WORKERS processes.

How to add sponsored channel for MTProto proxy (MTProxy)?
This is how the sponsor channel looks when MTProxy is enabled in @BestMTProxyBot (you need to connect to the second server from the list provided).
In the case of the SOCKS5 server, any Telegram user can use a proxy created and maintained by a public that he does not read, and perhaps does not even know about its existence. In the case of MTProto server, you have to pay for using the service by subscribing to the channel.

Telegram has implemented monetization for proxy server owners through sponsor's proxy advertising. Proxy sponsor is a channel that will be pinned at the top of all dialogs and cannot be hidden from the top until you disconnect from the current proxy server or subscribe.

You can show your own channel, and recoup the costs of maintaining the server by selling advertising in it. Or, if the owner does not want to engage in maintaining the Telegram channel, he can charge a fee for placing someone else's public on the Promoted channel.

To bind to the sponsor proxy server, first obtain the hexadecimal code from the @MTProxybot service bot. Then it must be passed at server start as the value of the TAG variable:
Code:
docker run -d -p443:443 -v proxy-config:/data -e TAG=3f40462915a3e6026a4d790127b95ded telegrammessenger/proxy:latest

Please note that the TAG variable is not saved: you will have to re-set it in the settings every time you start or recreate the proxy container.
 
Top