简介
MTProxy 是在新版本 Telegram 中内置的代理程序,如果只是为了上tg而挂个酸酸,可能会比较耗电,
MTProxy的命名,大概和MTProto有关
Telegram 团队使用自己设计的加密协议 MTProto ,并以 30 万美金的高价奖赏漏洞的提交者。tg使用基于 MTProto 的通讯协议。
MTProxy开源地址:https://github.com/TelegramMessenger/MTProxy
部署
使用docker部署(推荐)
官方bot的推荐方法
- 使用一键脚本安装docker:
1
|
curl -sSL https://get.docker.com/ | sh
|
- 运行
1
2 |
service docker start
docker run -d -p443:443 --name=mtproto-proxy --restart=always -v proxy-config:/data telegrammessenger/proxy:latest
|
- 查看密钥
1
|
docker logs mtproto-proxy
|
你会看到:
1 2 3 4 5 6 7 8 9 |
[+] 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 [*] External IP: 3.14.15.92 [*] Make sure to fix the links in case you run the proxy on a different port. |
其中:
1
|
tg://proxy?server=3.14.15.92&port=443&secret=00baadf00d15abad1deaa515baadcafe
|
便是MTProxy的地址设置了。
直接复制到telegram客户端里面,再点击,会弹出设置询问你要不要设置。
当然上面这条是官方实例的,是不能用的。
https://hub.docker.com/r/telegrammessenger/proxy/
直接部署
直接部署可能会比较麻烦
安装依赖
需要安装一些编译的必要工具,以及openssl
和zlib
的开发包。
ubuntu/debian:
1
|
apt install git curl build-essential libssl-dev zlib1g-dev
|
centos/RHEL:
1 2 |
yum install openssl-devel zlib-devel yum groupinstall "Development Tools" |
克隆仓库:
1 2 |
git clone https://github.com/TelegramMessenger/MTProxy cd MTProxy |
编译,只需要运行make
,二进制文件会保存在objs/bin/mtproto-proxy
1
|
make && cd objs/bin
|
如果编译失败了,在下次编译之前要运行make clean
清理失败的文件。
运行
- 获取用于连接到telegram 服务器的密钥:
1
|
curl -s https://core.telegram.org/getProxySecret -o proxy-secret
|
- 获取现在telegram服务器的配置。配置有时候会变,所以我们建议你每天更新
1
|
curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf
|
- 生成一个密钥,以用于用户连接到你的代理:
1
|
head -c 16 /dev/urandom | xxd -ps
|
- 运行
mtproto-proxy
:
1
|
./mtproto-proxy -u nobody -p 8888 -H 443 -S |
参数说明:
nobody
是用户名.mtproto-proxy
调用setuid()
来放弃权限.443
是指端口,用来客户端连接到代理。8888
是本地端口。你可以用它来获取mtproto-proxy
的统计数据。比如wget localhost:8888/stats
. 你只能从环回网口得到这个统计数据。
是步骤三中生成的密钥.你还可以设置多个密钥:-S
。-S proxy-secret
和proxy-multi.conf
是从步骤一和步骤二获取的。1
是工作的进程数.如果你有一个配置很好的服务器,你可以增加工作进程数。
你还可以用mtproto-proxy --help
来查看其他设置。
- 用指定格式生成链接:
tg://proxy?server=SERVER_NAME&port=PORT&secret=SECRET
,或者让bot帮你生成。 - 在telegram上用@MTProxybot注册你的代理
- 用
-P
参数设置接受tag:-P
Systemd 配置示例
- 创建
systemd
服务文件 (这是大多数Linux发行版的标准路径,但您应该先查看它):
1
|
nano /etc/systemd/system/MTProxy.service
|
- 修改这个基础服务(尤其是路径和参数):
1 2 3 4 5 6 7 8 9 10 11 12 |
[Unit] Description=MTProxy After=network.target [Service] Type=simple WorkingDirectory=/opt/MTProxy ExecStart=/opt/MTProxy/mtproto-proxy -u nobody -p 8888 -H 443 -S |
- 重新加载守护进程:
1
|
systemctl daemon-reload
|
- 测试MTProxy服务:
1 2 3 |
systemctl restart MTProxy.service # Check status, it should be active systemctl status MTProxy.service |
设置开机自启:
1
|
systemctl enable MTProxy.service
|
后续
需要在官方的 @MTProxybot 注册你的MTProxy代理才可以使用。注册完成后,bot提示你,代理可以共享给其他人用,并且可以设置一个频道链接作为 promotion(推广),如果有人使用了你的代理,他的客户端会置顶你的channel,显示proxy sponsor(代理提供者),点进去,在join channel一栏上面写着:
1
|
This channel is shown by your proxy server.To remove this channel from your chats list, disable the proxy in Telegram Settings.
|