Fast and simple to setup MTProto proxy written in Python.
- Pull the latest image:
docker pull ghcr.io/xrh0905/mtprotoproxy:latest - (optional, recommended) create a config.py file, set PORT, USERS and AD_TAG
- Run the container:
docker run -d --name mtprotoproxy \ --network host \ -v $(pwd)/config.py:/home/tgproxy/config.py \ ghcr.io/xrh0905/mtprotoproxy:latest - (optional, get a link to share the proxy)
docker logs mtprotoproxy
git clone -b edge https://github.com/xrh0905/mtprotoproxy.git; cd mtprotoproxy- (optional, recommended) edit config.py, set PORT, USERS and AD_TAG
docker build -t mtprotoproxy .docker-compose up -d(or justpython3 mtprotoproxy.pyif you don't like Docker)- (optional, get a link to share the proxy)
docker-compose logs
You can use the pre-built image with docker-compose by updating your docker-compose.yml:
version: '3.8'
services:
mtprotoproxy:
image: ghcr.io/xrh0905/mtprotoproxy:latest
restart: unless-stopped
network_mode: "host"
environment:
# Core configuration - replace these values with your own
- PORT=443
- TG_KEY=00000000000000000000000000000001
- SECURE_ONLY=true
- TLS_ONLY=true
- TLS_DOMAIN=www.drive.google.com
- AD_TAG=3c09c680b76ee91a4c25ad51f742267d
# Optional: Performance tuning
# - TO_CLT_BUFSIZE=65536
# - TO_TG_BUFSIZE=65536
# Optional: Metrics
# - METRICS_PORT=9090
volumes:
- ./config.py:/home/tgproxy/config.pyThen run: docker-compose up -d
To advertise a channel get a tag from @MTProxybot and put it to config.py.
All configuration options can be set via environment variables. This is particularly useful when running in Docker.
| Variable | Default | Description |
|---|---|---|
PORT |
443 |
Listening port for the proxy |
TG_KEY |
00000000000000000000000000000001 |
User secret (32 hex characters) |
AD_TAG |
3c09c680b76ee91a4c25ad51f742267d |
Tag for advertising, obtainable from @MTProxybot |
| Variable | Default | Description |
|---|---|---|
SECURE_ONLY |
true |
Makes the proxy harder to detect (incompatible with very old clients) |
TLS_ONLY |
true |
Makes the proxy even harder to detect (compatible only with recent clients) |
TLS_DOMAIN |
www.google.com |
Domain for TLS, bad clients are proxied there |
| Variable | Default | Description |
|---|---|---|
SOCKS5_HOST |
None |
SOCKS5 proxy hostname or IP address |
SOCKS5_PORT |
None |
SOCKS5 proxy port |
SOCKS5_USER |
None |
SOCKS5 username (optional) |
SOCKS5_PASS |
None |
SOCKS5 password (optional) |
Note: When SOCKS5 is enabled, middle proxy advertising is automatically disabled.
| Variable | Default | Description |
|---|---|---|
TO_CLT_BUFSIZE |
16384,100,131072 |
Buffer size to client. Single integer or comma-separated tuple (low,users_margin,high) for adaptive sizing |
TO_TG_BUFSIZE |
65536 |
Buffer size to Telegram servers. Single integer or comma-separated tuple for adaptive sizing |
STATS_PRINT_PERIOD |
600 |
Statistics print period in seconds |
CLIENT_KEEPALIVE |
600 |
Client keepalive period in seconds (10 minutes) |
TG_CONNECT_TIMEOUT |
10 |
Telegram server connect timeout in seconds |
FAST_MODE |
true |
Enable fast mode (disables some checks for better performance) |
| Variable | Default | Description |
|---|---|---|
LISTEN_ADDR_IPV4 |
0.0.0.0 |
IPv4 listen address |
LISTEN_ADDR_IPV6 |
:: |
IPv6 listen address |
PREFER_IPV6 |
Auto-detected | Prefer IPv6 for outgoing connections |
| Variable | Default | Description |
|---|---|---|
METRICS_PORT |
None |
Prometheus exporter listen port (set to enable metrics) |
METRICS_EXPORT_LINKS |
false |
Export proxy links in metrics |
docker run -d --name mtprotoproxy \
--network host \
-e PORT=8443 \
-e TG_KEY=00000000000000000000000000000001 \
-e SECURE_ONLY=true \
-e TLS_ONLY=true \
-e TLS_DOMAIN=www.google.com \
-e AD_TAG=3c09c680b76ee91a4c25ad51f742267d \
-e TO_CLT_BUFSIZE=65536 \
-e TO_TG_BUFSIZE=65536 \
-e METRICS_PORT=9090 \
ghcr.io/xrh0905/mtprotoproxy:latestThe proxy performance should be enough to comfortably serve about 4 000 simultaneous users on the VDS instance with 1 CPU core and 1024MB RAM.
The proxy can be launched:
- with a custom config:
python3 mtprotoproxy.py [configfile] - several times, clients will be automaticaly balanced between instances
- with uvloop module to get an extra speed boost
- with runtime statistics exported to Prometheus
You can configure the MTProto proxy to use a SOCKS5 proxy for outgoing connections to Telegram servers. This is useful when your server cannot directly connect to Telegram or you want to route traffic through another proxy.
Note: SOCKS5 mode is incompatible with middle proxy advertising.
Add the following settings to your config.py:
# SOCKS5 proxy settings (optional)
SOCKS5_HOST = "your.socks5.server.com" # SOCKS5 proxy hostname or IP
SOCKS5_PORT = 1080 # SOCKS5 proxy port
SOCKS5_USER = "username" # Optional: SOCKS5 username (set to None if not needed)
SOCKS5_PASS = "password" # Optional: SOCKS5 password (set to None if not needed)You can also configure SOCKS5 using environment variables:
docker run -d --name mtprotoproxy \
--network host \
-e SOCKS5_HOST=your.socks5.server.com \
-e SOCKS5_PORT=1080 \
-e SOCKS5_USER=username \
-e SOCKS5_PASS=password \
-v $(pwd)/config.py:/home/tgproxy/config.py \
ghcr.io/xrh0905/mtprotoproxy:latestversion: '3.8'
services:
mtprotoproxy:
image: ghcr.io/xrh0905/mtprotoproxy:latest
restart: unless-stopped
network_mode: "host"
environment:
- TG_KEY=00000000000000000000000000000001
- SECURE_ONLY=true
- TLS_ONLY=true
- TLS_DOMAIN=www.drive.google.com
# SOCKS5 proxy configuration
- SOCKS5_HOST=your.socks5.server.com
- SOCKS5_PORT=1080
- SOCKS5_USER=username
- SOCKS5_PASS=password
volumes:
- ./config.py:/home/tgproxy/config.pyImportant: When SOCKS5 is enabled:
- The middle proxy feature is automatically disabled
- Channel advertising may not work
