45 yuan/month to complete TCP long connection four-layer forwarding: Nginx stream practical operation + one-click script
need
TCP long connection, binary data transmission, about 1 TB/month, no anti-DDoS required. As long as there are one or two entry points, there is no need for nationwide multi-node acceleration.
Let’s talk about the conclusion first:This requirement requires Layer 4 forwarding, which Layer 7 CDN cannot handle.
Let’s sort out the pitfalls first: I’ve checked all these options, but none of them are suitable.
- Baidu CDN / Full Site Acceleration (DCDN):What we do is static, dynamic API, HTTP/2, QUIC and other seven-layer acceleration. No product description of TCP/UDP bare protocol and four-layer port transparent transmission was found. Its price of about 0.20 yuan/GB is only valid for HTTP/HTTPS services.
- Huawei WSA: The official FAQ only supports HTTP/HTTPS/WebSocket/gRPC and does not support any TCP naked binary.
- 123pan Enterprise Edition: File distribution, not forwarding.
Cheap volume-based pricing makes no sense, first check whether the agreement supports it. This is the biggest pitfall I've ever stepped into.
Plan comparison (1 TB/month, Mainland China)
| plan | Approximate monthly cost | Applicable |
|---|---|---|
| Tencent lightweight Ruichi 2-core 2G self-built Nginx stream | 45 yuan | Single point of entry, recommended in this article |
| High-defense CDN monthly 1 TB file | 698 yuan | I want a monthly subscription, but I don’t want to build it myself. |
| Tencent EdgeOne L4 (Enterprise Edition) | About 1,190 yuan | Multiple nodes nationwide |
| Alibaba Cloud DCDN IPA | About 1,380 yuan | Endorsed by multiple nodes and major manufacturers across the country |
| Huawei GA | About 2,080 yuan + instance/CU fee | Not recommended for this volume |
The price is subject to the settlement page; the Rui Chi model of 45 yuan/month is subject to Tencent Cloud's official "Price Overview" PDF (updated on 2026-11-11).
First choice: Tencent Cloud Lightweight Ruichi 2-core 2G, 45 yuan/month
Configuration: Mainland China 2-core 2G/40GB SSD/peak 200Mbps/unlimited traffic (annual payment is 459 yuan).
Note: 200 Mbps is the peak value, not the exclusive committed bandwidth, may fall back during peak competition. 1 TB/month only averages about 3 Mbps, the average volume is not the bottleneck, the peak is the deciding factor.
Purchase list: Select the region in mainland China closest to the backend/main client (Shanghai, Beijing, Guangzhou, Chengdu, Nanjing are optional); system Ubuntu 22.04/24.04 LTS (Nginx includes the stream module, Ubuntu comes with the default package); the security group only allows the listening port, and the rest are closed; the origin site only allows the transit IP to connect to the backend port.
The lightweight package can only be upgraded but not downgraded, and configurations cannot be changed across series. The default quota for a single region is 5 units. It is a more stable path to buy a small one first and test it before upgrading.
Decision table: only 4 numbers left
| your situation | Selection method |
|---|---|
| Peak bandwidth ≤ about 50 Mbps (sustained), concurrent long connections ≤ about 10,000 | Ruichi type 2 core 2G, 45 yuan/month, enough |
| Peak 50–200 Mbps in short bursts | Same as above, first buy the 45 yuan file and see the actual peak fallback situation |
| Peak sustained > 100 Mbps, or concurrent > ~20k | Consider Ruichi 4-core 8G, 230 yuan/month, or switch to CVM and charge according to bandwidth. |
| The backend needs to get the real client IP | Use the PROXY protocol version configuration below, and the backend must support parsing |
| Clients are spread all over the country and require low latency nearby. | If the self-built single point is not enough, use Alibaba Cloud DCDN IPA, about 1.38 yuan/GB. |
Nginx stream configuration (fill in the backend address to use)
# /etc/nginx/nginx.conf —— 在 events{} 之后、http{} 之外加入
stream {
upstream backend {
server 目标IP:目标端口;
}
server {
listen 监听端口;
proxy_pass backend;
proxy_connect_timeout 10s;
proxy_timeout 24h; # 长连接:别用默认短超时
proxy_socket_keepalive on;
tcp_nodelay on;
}
}
When using high concurrency and long connections, add (top level + sysctl, execute sysctl -p):
worker_processes auto;
worker_rlimit_nofile 65535;
events {
worker_connections 16384;
}
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.ip_local_port_range = 1024 65535
fs.file-max = 200000
One-click installation script
The script is ready: change the top 3 values (BACKEND_IP、BACKEND_PORT、LISTEN_PORT), and then on the lightweight machine sudo bash nginx-stream-install.sh. It will install Nginx, backup the original nginx.conf, write the above stream configuration, perform high concurrency tuning,nginx -t Reload only after passing, and finally print the following 4 tests.
When real client IP is required:Bundle ENABLE_PROXY_PROTOCOL=true, and the backend must have PROXY protocol resolution enabled.Do not enable it when the backend does not support parsing., otherwise the backend will treat the PROXY header as business data. The default is turned off, and the backend sees the transit IP.
Test before going live (5 minutes)
sudo nginx -t && sudo systemctl reload nginx
# 1. 透传:从客户端发一段二进制,对比后端收到的数据是否逐字节一致
# 2. 长连接:保持连接空闲 1 小时以上,确认不被 proxy_timeout 断开
# 3. 峰值:用真实客户端压到预期峰值带宽,观察 200Mbps 峰值下是否回落
# 4. 断线重连:杀掉后端一次,确认客户端重连后恢复
ss -tnp | grep :监听端口 # 看并发连接数
Be honest
The configuration and script of this article are the deployment packages I compiled on 2026-11-25. The price was verified from Tencent Cloud official information, and the exclusions were also checked from official sources; but I have not yet bought this lightweight machine and run it on a real machine, and the peak drop and concurrency upper limit are still to be tested. If you have already run something of similar magnitude, please post your actual measured data in the comments and I will update it.
There are no messages yet. please Log in or Register an account Start this discussion.