花了一笔不小的预算在 Netcup 购买了一台 美国 4 核 8G 的 Root Server(RS),在正式使用前,我想先弄清楚一件事:
本地网络到这台 VPS 的真实连接质量到底如何?
为此,我在服务器上部署了一个开源测速应用 Speedtest-X,用来自测延迟、下载和上传速度。下面记录完整搭建过程。
一、登录服务器并安装 Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
安装完成后,启动 Docker 并设置开机自启:
systemctl enable docker --now
确认是否安装成功:
docker version
二、使用 Docker Compose 部署 Speedtest-X
1. 创建目录并进入
mkdir -p /root/speedtest
cd /root/speedtest
2. 创建 docker-compose.yml
nano docker-compose.yml
将以下内容粘贴进去:
version: '3.3'
services:
speedtest-x:
image: badapple9/speedtest-x
container_name: speedtest-x
restart: always
ports:
- "8080:80" # 对外 8080,容器内 80
tty: true
保存并退出(Ctrl + O → 回车 → Ctrl + X)。
三、配置 Nginx 反向代理 + HTTPS(非必须)
1. 准备域名
先给测速服务准备一个域名,例如:
speedtest.example.com
在 DNS 中添加一条 A 记录,指向服务器 IP。
2. 安装 Nginx 和 Certbot
apt update
apt install -y nginx certbot python3-certbot-nginx
3. 配置 Nginx 反向代理
创建配置文件:
nano /etc/nginx/sites-available/speedtest
写入以下内容(注意替换域名):
server {
listen 80;
server_name speedtest.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
启用站点并重载 Nginx:
ln -s /etc/nginx/sites-available/speedtest /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx
4. 申请 HTTPS 证书
certbot --nginx -d speedtest.example.com
四、访问测速页面
现在可以直接通过浏览器访问:
https://speedtest.example.com
即可看到 Speedtest-X 的测速界面,测试本地网络到 VPS 的真实连接情况。
五、常见问题说明
为什么必须使用 HTTPS?
Speedtest-X 使用浏览器相关接口,HTTP 环境下会被直接限制,测速无法正常运行。
会不会消耗大量流量?
一次完整测速通常会消耗 50MB–200MB 流量,频繁测试需注意服务器月流量配额。
能否限制滥用?
如果公开使用,建议:
加 Cloudflare
或在 Nginx 中限制并发
或仅供自己测试,不对外公开
六、总结
通过 Speedtest-X 自建测速服务,可以更直观地了解 本地网络到 VPS 的真实延迟与带宽情况,相比公共测速站更贴近实际使用体验。
对于刚买服务器、需要评估线路质量的场景,这种方式非常实用。