When operating a self-hosted Telegram Bot system, there will be times when you need to upgrade resources or change your hosting provider. The migrating Telegram Bot server needs to be carried out carefully to avoid service disruption and protect user data. This article will guide you through a detailed, safe migration process from an old server to a new server using Nginx Proxy Manager.
For developers operating large systems, self-hosting a local Telegram Bot API server offers many outstanding benefits. It allows you to send large files up to 2GB instead of the 50MB limit of the public Telegram server. However, when the infrastructure changes, you must know how to move a Telegram Bot server to maintain service stability without losing important webhook packets from users.
Why do you need to move your Telegram Bot server?
There are many reasons why developers decide migrating Telegram Bot server after a period of operation. The most common cause is that the number of users and the bot's data grow rapidly, exceeding the resource limits of the old Cloud VPS. When that happens, slow responses, network congestion, or buffer memory overflow occur continuously, directly affecting user experience.
Additionally, shifting the management model is also a major driver. Many businesses are moving from bulky management systems such as CyberPanel to leaner, easier-to-maintain models such as Docker combined with Nginx Proxy Manager. This optimization helps improve the overall operational performance of the Telegram Bot service currently running on your system.
Whatever the reason, careful planning before getting started is extremely important. A bot system is not simply a standalone application; it is directly related to Telegram webhooks, SSL/TLS security certificates, and managing the disk space that holds temporary data files.

Preparation steps before moving the server
Before running any migration commands, you need to back up the entire current configuration of the old server. This helps you quickly restore the system if issues occur during the new environment setup.
First, identify the launch parameters of the old API process. Typically, this process runs as a system service (systemd service) or a Docker container. You need to accurately record the API ID and API Hash obtained from Telegram's configuration page, as well as the path where temporary files are stored.
Second, verify the SSH port and security settings on both VPS instances. Knowing clearly how to move a Telegram Bot server will help you prepare better, for example by opening the necessary network ports on the new server's firewall in advance so as not to interrupt the webhook data flow after pointing the DNS.
Detailed 4-Step Process for Migrating a Telegram Bot Server
The migration process is divided into 4 clear steps to ensure data integrity and minimize service interruption time (downtime) as much as possible.
Step 1: Copy the Executable File (Binary) and Configure the Service
To save time, you can directly copy the executable file telegram-bot-api already compiled from the old VPS to the new VPS instead of having to recompile from scratch (usually taking 30 to 60 minutes). Copying the binary during the process migrating Telegram Bot server helps significantly shorten the actual deployment time.
First, access the new VPS via SSH and create the necessary directories:
mkdir -p /root/telegram-bot-api/bin
mkdir -p /var/lib/telegram-bot-api-tmp
chmod 777 /var/lib/telegram-bot-api-tmp
Next, run the command scp on the new VPS, download the binary file directly from the old VPS. Assuming the SSH port of the old VPS is 24700 and the IP address of the old VPS is 103.72.98.XX (IP information has been hidden for security):
scp -P 24700 root@103.72.98.XX:/root/telegram-bot-api/bin/telegram-bot-api /root/telegram-bot-api/bin/telegram-bot-api
chmod +x /root/telegram-bot-api/bin/telegram-bot-api
Check whether the executable file runs properly on the new VPS environment when proceeding migrating Telegram Bot server:
/root/telegram-bot-api/bin/telegram-bot-api --help
If the system reports missing shared libraries libc++.so.1, you only need to run the following command to install the additional C++ library of LLVM:
sudo apt update && sudo apt install libc++1 libc++abi1 -y
After a successful test run, create a systemd service file to manage the background process of the bot on the new VPS:
nano /etc/systemd/system/telegram-bot-api.service
Add the service configuration content below to the file. Instructions migrating Telegram Bot server this uses optimized parameters that help the service automatically restart when errors occur:
[Unit]
Description=Telegram Bot API Server
After=network.target
[Service]
ExecStart=/root/telegram-bot-api/bin/telegram-bot-api \
--api-id=21011591 \
--api-hash=f7f3807f0bcde0928c3ae6c3a28d154f \
--local \
--verbosity=1 \
--temp-dir=/var/lib/telegram-bot-api-tmp
Restart=always
User=root
[Install]
WantedBy=multi-user.target
Activate and start the service on the new VPS to complete the platform setup:
systemctl daemon-reload
systemctl enable telegram-bot-api
systemctl start telegram-bot-api
Check the operating status to ensure the service is listening on port 8081 of the new VPS:
systemctl status telegram-bot-api
ss -tulpn | grep 8081
Step 2: Configure Reverse Proxy via Nginx Proxy Manager
Configure the connection port for migrating Telegram Bot server through a reverse proxy is required to encrypt the connection using SSL. When using Nginx Proxy Manager running in Docker as the domain management gateway, connecting to a service running directly on the server's operating system requires attention to the internal Docker network routing.
During the migrating Telegram Bot server, you cannot enter the forwarding IP as 127.0.0.1 because Docker will automatically look for that port inside its own container, not on the physical host. Nginx Proxy Manager plays a central role when migrating Telegram Bot server because it receives HTTPS requests from Telegram and forwards HTTP to port 8081 of the server.
Configure the Proxy Host in the Nginx Proxy Manager interface using the following detailed parameters:
- Details Tab:
- Domain Names: Enter your subdomain (for example:
tele.dpsmedia.vn). - Scheme: Select
http. - Forward Hostname / IP: Enter the default gateway IP of Docker
172.17.0.1(or the public IP of the new VPS103.72.96.YY). Configure redirects that allow migrating Telegram Bot server operating smoothly without encountering obstacles related to Docker network routing. - Forward Port: Enter
8081. - Websockets Support: Enable (toggle the switch to ON).
- Domain Names: Enter your subdomain (for example:
- SSL Tab:
- SSL Certificate: Select Request a new SSL Certificate from Let’s Encrypt to provide secure encryption.
- Force SSL: Enable to automatically redirect all HTTP requests to HTTPS. SSL is mandatory for migrating Telegram Bot server running stably because Telegram only accepts HTTPS connections for webhooks.
- HTTP/2 Support and HSTS Enabled: Enable both to increase transmission speed and strengthen security barriers.
- Tab Advanced:
- Enter the following Nginx configuration snippet to increase the upload file size limit and prevent timeout errors when the bot processes large files (by default, Nginx only allows uploading files under 1MB):
client_max_body_size 2000M; proxy_read_timeout 600s; proxy_send_timeout 600s;
- Enter the following Nginx configuration snippet to increase the upload file size limit and prevent timeout errors when the bot processes large files (by default, Nginx only allows uploading files under 1MB):
Save the configuration again. Nginx Proxy Manager will automatically perform the verification process with Let’s Encrypt to issue a new SSL certificate for your domain name.
Step 3: Update DNS and Check SSL
Update DNS to complete the setup migrating Telegram Bot server is a critically important step to reroute all Telegram webhooks from the old server to the new server. After migrating Telegram Bot server, update the domain's A record to point to the new VPS IP address.
Access your domain management panel (for example: Cloudflare, Google Domains, or a domain provider in Vietnam) and edit the current record:
- Record Type (Type):
A - Name (Name):
tele(or your corresponding subdomain) - IPv4 Address (Value):
103.72.96.YY(IP of the new VPS, security information hidden) - TTL: Set the shortest TTL (for example, 2 minutes or Auto) so the record propagates faster across the internet.
After saving the new DNS record, please wait about 5-10 minutes for DNS to fully update. This is a mandatory part of the learning process how to move a Telegram Bot server which every developer needs to master.
Step 4: Configure the Cron Job to Clean Up Temporary Memory
Cleaning up the hard drive is an indispensable part when migrating Telegram Bot server running in local mode (--local). When running in this mode, all image, video, and document files sent through the bot will be downloaded and stored directly in the temporary folder of the new VPS. Without regular cleanup, your VPS will quickly run out of storage capacity, leading to a full system freeze.
Temp directory of the migrating Telegram Bot server located at /var/lib/telegram-bot-api-tmp must be closely monitored. Open the root account's crontab on the new VPS:
sudo crontab -e
Add the following two command lines to the end of the file to set up an automatic hourly cleanup schedule:
0 * * * * find /var/lib/telegram-bot-api-tmp -type f -mtime +1 -delete
0 * * * * find /var/lib/telegram-bot-api-tmp -type f -size +100M -delete
The above command will automatically search for and delete all temporary files older than 1 day, or files larger than 100MB, to free up storage space on the VPS.
Post-Migration Verification and Testing
Checking operation is the final step of the migrating Telegram Bot server to ensure that the system is fully operational on the new infrastructure. From a personal computer or another server, run the command curl to check the response from your domain name:
curl -i https://tele.yourdomain.com/
If the HTTPS connection succeeds and Nginx Proxy Manager is working correctly, you will receive a JSON-formatted 404 error response directly from the Telegram Bot API server as follows:
HTTP/1.1 404 Not Found
Server: openresty
Content-Type: application/json
Content-Length: 55
Connection: keep-alive
{"ok":false,"error_code":404,"description":"Not Found"}
If curl succeeds, the process migrating Telegram Bot server has been completed. You can safely stop the old service after migrating Telegram Bot server has been running stably in the new environment for 24 hours. Access the old VPS and run the service stop commands to free up resources:
sudo systemctl stop telegram-bot-api
sudo systemctl disable telegram-bot-api

Conclusion and Optimal System Solution from DPS.MEDIA
In summary, the migrating Telegram Bot server requires careful attention and correct sequencing, from migrating the source code and configuring the reverse proxy to setting up periodic system cleanup. Understanding this process clearly helps developers confidently manage their application infrastructure without worrying about connection interruptions.
If your business needs to build an automated customer care bot system, integrate AI, or optimize professional Cloud VPS infrastructure, please contact us right away. DPS.MEDIA is proud to provide comprehensive technology optimization solutions that help your business operate most efficiently. Please visit our homepage for more information to stay updated on the latest solutions for information technology systems and DPS.MEDIA's SEO optimization services.
We hope this article will guide migrating Telegram Bot server this will help you migrate the system successfully and securely. To learn more about application configuration and interaction methods, you can refer to additional resources Telegram's official API documentation.
Copyright of this article belongs to DPS.MEDIA JSC.
Ý kiến bạn đọc (8)
Đăng nhập để bình luận
Đăng nhập nhanh 1-chạm bằng Google để chia sẻ ý kiến của bạn về bài viết.
Bằng cách đăng nhập, bạn đồng ý với điều khoản và chính sách cộng đồng.
We once moved a bot to a new VPS but lost webhooks during the DNS change. Following this process, how long should the old and new servers run in parallel to reduce risk?
Prepare all services, the reverse proxy, and SSL on the new machine first, then switch DNS. Keep the old server running as is until webhooks and logs on the new machine are verified as stable, and only then shut it down.
Absolutely agreed, the DNS part shouldn't be changed too early. We usually test in a new environment first, then monitor actual requests after the DNS update to avoid handling two places at once.
My main interest is the section on Nginx Proxy Manager and SSL. If the bot is running fine on the old server, do I need to reissue the SSL certificate when moving to a new VPS, and how long does the actual downtime usually last?
SSL usually needs to be reconfigured on the new proxy environment, but it can be prepared before the DNS change, so downtime can be kept to a minimum. What matters is checking the domain, connection ports, and certificate status before shifting traffic.
Backing up before moving to a new server is extremely important. With copies of the binary, the service configuration, and the necessary data, you can still roll back to the old server if an incident occurs.
If the bot processes many large files, check the disk capacity and network speed of the new VPS carefully. Looking only at CPU and RAM is not enough.
The cron job for clearing temporary memory is very practical. If the bot runs for a long time and temporary files are forgotten, the disk can fill up without anyone noticing.
Chưa có bình luận nào. Hãy là người đầu tiên chia sẻ cảm nghĩ!
Đăng nhập / Tạo tài khoản
Đăng nhập với Google để gửi bình luận và tương tác cùng cộng đồng.
Tiếp tục là đồng ý với điều khoản sử dụng và chính sách bảo mật của DPS Media.