
🌐 이 글의 한국어 원문이 있습니다.한국어 원문 보기 →
Let's Build Our Own Speedtest Server
While laying new cabling for our internal network, I needed a speed test to check that gigabit was actually working.
But when I tried to run a test on speedtest.net, maybe because it was Friday, the connection just wasn't going smoothly. At this rate, the whole thing would end with it still looking for a server...

Testing is at least easier with the terminal command speedtest-cli, because you can specify the server directly. On the web, it ends with it still searching for a server, but if you specify the server yourself on the command line, it skips the server search and goes straight into the test. If you put a server ID in the command, you can query that server directly. The ID for the Korean server is 6527.
speedtest-cli --server 6527But while playing around with the speedtest-cli command, I learned that you can specify something called a 'mini server'.
% speedtest-cli --help
...
--mini MINI URL of the Speedtest Mini server
...I wondered whether that meant I could build a server locally and use it, so I looked it up, and building one was indeed possible (how to build a speedtest-cli server).
Building it is simple, but no matter how many times I built and tested it, it just wouldn't work. Maybe because I hadn't set up HTTPS certificates, it kept throwing errors.
% speedtest-cli --mini http://172.168.0.1:8080
Retrieving speedtest.net configuration...
Testing from Korea Telecom (181.***.***.***)...
ERROR: Invalid Speedtest Mini Server: http://172.168.0.1:8080It was the same when I specified a host name instead of an IP. When I checked with the tester provided by Ookla, I didn't see any errors other than HTTS not being applied. I couldn't register the mini server either, and while I suspected the missing HTTPS was the cause, it wasn't a server where I could apply that however I liked, so I gave up on it.
(I found out later that Ookla's speedtest and speedtest-cli are two different things. Not knowing this, I diligently installed the Ookla server and then pointed speedtest-cli at it as a 'mini server'. After confirming that speedtest-cli supports the --debug parameter, I used it to paste the 'get' URLs directly into a web browser for comparison, and realized the two communicate in different ways. And sadly... the mini server source is no longer maintained.)
After finishing the job by slowly running tests with the server-specified terminal command, I looked around and found LibreSpeed, which you can serve on the web and test with. Partly to double-check my work afterward, I quickly installed it on a test virtual server and gave it a try.
For installation, I referred to a post shared by 2cpu member 무한도전 ("Infinite Challenge") (2cpu is a Korean hardware community). It was based on CentOS 7.3, but applying it on Ubuntu was no trouble (for reference, my test server is an old Ubuntu 12.04 server). All you need is PHP and a web server (Apache or NGINX) that can serve HTTP. You can also configure SQL (SQLITE, MYSQL, POSTGRESQL) to store test results, but testing works perfectly well without SQL. For commands, you need wget and unzip.
First, download it and unzip it.
wget https://github.com/librespeed/speedtest/archive/master.zip
unzip master.zip*If git is installed, you can also clone it with git.
git clone https://github.com/librespeed/speedtest.gitOnce unzipped, you'll find files like the ones below.

From these files, I'll make a folder to put on the web server.
cd speedtest-master/
mkdir ../speedtest
mv backend/ ../speedtest/
cp speedtest* ../speedtest/
mv examples/example-singleServer-progressBar.html ../speedtest/index.htmlThis gathers the files you need in a folder named speedtest. After that, put the folder in the web server folder and set the permissions.
sudo cp -r speedtest /var/www/html
cd /var/www/html
sudo chown -R www-data:www-data speedtest/*From Ubuntu 14.04 onward, /var/www/html is the web server folder, so watch the path.
Then open that server path http://서버_주소/speedtest (서버_주소 means "server address") in a web browser and run the test.

I spent over two hours fumbling around trying to build a speedtest-cli server, but this took less than 20 minutes. Queries are much faster than with speedtest-cli, too.
It was a bit of a shame that I couldn't query it from a terminal command, but I looked around and found librespeed-cli, which works from the terminal. On Linux it uses go, so having to install go is a bit of a hassle.
sudo apt install golang-go
git clone https://github.com/librespeed/speedtest-cli
cd speedtest-cli
./build.sh
cd out
sudo mv ./librespeed-cli-linux-amd64 /usr/bin/librespeed-cliOn OS X, you can install it with just a command from hombrew.
brew tap librespeed/tap
brew install librespeed-cliBy default, the command points to liberespeed's public servers, so when you run it you'll see it running a speed test against a server in the US. To point it at a local server, you need to create a server list config file in json. Creating a config file after installing on every computer would be tedious, but with liberespeed you can put the server list config file on the 'server' and point to it. Just put the config file on the server and point to it there.
sudo touch /var/www/speedtest/server_list.json
sudo chown www-data:www-data /var/www/speedtest/server_list.json
sudo chmod 660 /var/www/speedtest/server_list.json
sudo vi /var/www/speedtest/server_list.jsonThen save the server list in the file as shown below. For the server path, it has to point to each of the PHP files, so you need to add backend at the end. Since this is a server list, you can also list multiple servers.
[
{
"id": 1,
"name": "PHP Backend",
"server": "http://서버_주소/speedtest/backend",
"dlURL": "garbage.php",
"ulURL": "empty.php",
"pingURL": "empty.php",
"getIpURL": "getIP.php"
}
]After that, open http://서버_주소/speedtest/server_list.json in a web browser and confirm that the same content shows up.
Now, on the computer whose speed you want to check, enter the command below and it will check the speed along with the ping.
% librespeed-cli --server-json http://서버_주소/speedtest/server_list.json
Retrieving server list from http:/서버_주소/speedtest/server_list.json
Selecting the fastest server based on ping
Selected server: PHP Backend [서버_주소]
You're testing from:
Ping: 0 ms Jitter: 0 ms
Download rate: 935.35 Mbps
Upload rate: 693.24 MbpsWhen testing in the browser, the download speed never went above 700 Mbps, but on the CLI the download speed comes close to 1 Gbps. During the test, other browser activity connected to the web server even stuttered. It seems to test by using as much of the network resources as it can possibly pull.
For local environments, there's a great tool called LibreSpeed, so don't needlessly stick to just Ookla's speedtest or speedtest-cli like I did. With a simple build and setup, I got very satisfying results.sudo apt install golang-go

