Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What are the steps to configure MTProxy on a VPS


What are the steps to configure MTProxy on a VPS


To configure an MTProxy on a VPS, you can follow these detailed steps. The process involves setting up the necessary dependencies, downloading the MTProxy source code, building it, and configuring it to run as a service. Below are the steps tailored for an Ubuntu 22.04 server, but similar steps can be applied to other Linux distributions.

Step 1: Launch Your VPS

1. Choose a VPS provider (e.g., AWS Lightsail, DigitalOcean).
2. Launch a clean Ubuntu 22.04 instance with sufficient resources (512MB RAM is typically enough for basic usage).

Step 2: Connect to Your VPS

Use SSH to connect to your server:

bash
ssh ubuntu@<your_server_ip>

Step 3: Update the System

Update your package lists:

bash
sudo apt-get update

Step 4: Install Dependencies

Install the required packages to build MTProxy:

bash
sudo apt install git curl build-essential libssl-dev zlib1g-dev

Step 5: Clone the MTProxy Repository

Clone a community-maintained fork of MTProxy:

bash
git clone https://github.com/GetPageSpeed/MTProxy
cd MTProxy

Step 6: Build the MTProxy Binaries

Modify the `Makefile` to include the `-fcommon` flag, then build the binaries:

bash
nano Makefile

Add `-fcommon` to `CFLAGS` and `LDFLAGS`, then save and exit.

Now build:

bash
make

Step 7: Move the Binary to a Suitable Directory

Move the compiled binary to `/opt/MTProxy`:

bash
sudo mkdir /opt/MTProxy
sudo cp objs/bin/mtproto-proxy /opt/MTProxy/

Step 8: Create a Systemd Service File

Create a service file for MTProxy:

bash
sudo nano /etc/systemd/system/mtproxy.service

Insert the following configuration, replacing `` with a generated secret:

ini
[Unit]
Description=MTProxy
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/MTProxy
ExecStart=/opt/MTProxy/mtproto-proxy -u nobody -p 8888 -H 443 -S <SECRET> --aes-pwd proxy-secret proxy-multi.conf -M 1
Restart=on-failure

[Install]
WantedBy=multi-user.target

Step 9: Reload Systemd and Start the Service

Reload the systemd manager configuration:

bash
sudo systemctl daemon-reload

Start the MTProxy service:

bash
sudo systemctl start mtproxy.service

Check the status to ensure it is running:

bash
sudo systemctl status mtproxy.service

Step 10: Enable the Service on Boot

To ensure MTProxy starts on boot, enable the service:

bash
sudo systemctl enable mtproxy.service

Step 11: Automate Configuration Updates

Create a script to fetch the latest Telegram proxy configuration:

bash
sudo nano /opt/MTProxy/proxy-multi.sh

Add the following lines:

bash
#!/bin/bash
cd /opt/MTProxy
curl https://core.telegram.org/getProxyConfig > proxy-multi.conf
systemctl restart mtproxy.service

Make the script executable:

bash
sudo chmod +x /opt/MTProxy/proxy-multi.sh

Step 12: Set Up a Cron Job

Edit the crontab to run the script daily:

bash
crontab -e

Add the following line:

bash
0 0 * * * /bin/bash /opt/MTProxy/proxy-multi.sh

Conclusion

You have now configured MTProxy on your VPS. You can share the proxy details (server IP, port, and secret) with users who need to connect through Telegram. Ensure that your firewall allows traffic on the specified port (default is 443) for the proxy to function correctly[1][2][3][5].

Citations:
[1] https://github.com/HirbodBehnam/MTProtoProxyInstaller
[2] https://gist.github.com/rameerez/8debfc790e965009ca2949c3b4580b91?permalink_comment_id=4999582
[3] https://www.gadgethow2.com/2022/03/07/how-to-set-up-an-mtproto-mtproxy-telegram-proxy-server/
[4] https://v2how.github.io/post/2021-02-18-camouflage-telegram-mtproto-proxy-ubuntu-20-04/
[5] https://www.violetgem.com/blog/setup-telegram-mtproto-proxy-server/
[6] https://www.reddit.com/r/Telegram/comments/8lkw2z/how_to_create_a_mtproto_proxy_server/
[7] https://medium.com/%40getpagespeed/how-to-install-mtproxy-in-centos-redhat-7-9cd56aa19af6
[8] https://www.youtube.com/watch?v=_dc0m3kzmfo