Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What are the steps to configure MTProxy after launching the server


What are the steps to configure MTProxy after launching the server


To configure MTProxy after launching the server, follow these steps:

Step 1: Obtain Required Files

1. Get Proxy Secret: Run the following command to download the proxy secret from Telegram:

bash
   curl -s https://core.telegram.org/getProxySecret -o proxy-secret
   

2. Get Proxy Configuration: Download the current Telegram configuration:

bash
   curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf
   

3. Generate a Secret: Create a 16-character secret for user authentication:

bash
   head -c 16 /dev/urandom | xxd -ps
   

Step 2: Start MTProxy

Run the MTProxy with the following command, replacing `` with the secret generated in the previous step:

bash
./mtproto-proxy -u nobody -p 8888 -H 443 -S <secret> --aes-pwd proxy-secret proxy-multi.conf -M 1

Step 3: Create a Systemd Service

1. Copy MTProxy to the Appropriate Directory:

bash
   mkdir /opt/mtproxy
   cp /path/to/mtproto-proxy /opt/mtproxy/
   

2. Create a Systemd Service File:
Edit the service file:

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

Add the following content, adjusting paths and parameters as necessary:
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
   

3. Reload Systemd Daemons:

bash
   systemctl daemon-reload
   

4. Start and Enable the Service:

bash
   systemctl start mtproxy.service
   systemctl enable mtproxy.service
   

Step 4: Automate Configuration Updates

To keep the proxy configuration updated, create a script:

bash
nano /opt/mtproxy/proxy-multi.sh

Add the following content:
bash
#!/bin/bash
cd /opt/mtproxy
curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf
systemctl restart mtproxy.service

Make the script executable:
bash
chmod +x /opt/mtproxy/proxy-multi.sh

Set up a cron job to run this script daily:

bash
crontab -e

Add the following line:

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

Step 5: Verify the Setup

Check the status of the MTProxy service to ensure it is running:

bash
systemctl status mtproxy.service

This configuration will set up your MTProxy server to run continuously and update its configuration daily, ensuring it remains functional and secure[1][2][3].

Citations:
[1] https://github.com/HirbodBehnam/MTProtoProxyInstaller
[2] https://www.gadgethow2.com/2022/03/07/how-to-set-up-an-mtproto-mtproxy-telegram-proxy-server/
[3] https://gist.github.com/rameerez/8debfc790e965009ca2949c3b4580b91?permalink_comment_id=4999582
[4] https://www.reddit.com/r/Telegram/comments/8lkw2z/how_to_create_a_mtproto_proxy_server/
[5] https://aws.amazon.com/marketplace/pp/prodview-zefbfz6am5gu2
[6] https://www.adeoclouds.eu/aws-mtproxy.php
[7] https://www.violetgem.com/blog/setup-telegram-mtproto-proxy-server/
[8] https://medium.com/%40getpagespeed/how-to-install-mtproxy-in-centos-redhat-7-9cd56aa19af6