Requirements
- Go 1.13+ (or use prebuilt binary)
- A Go compatible platform
Note: Prebuilt binaries are not available yet.
Build from source
Install newer version of Go (if necessary)
$ go get golang.org/dl/go1.14.2
# Assuming your GOPATH is default (~/go), Go 1.14.2 will be installed in ~/go/bin
$ ~/go/bin/go1.14.2 version
go version go1.14.2 linux/amd64
Clone the repository
# Clone the repository
$ git clone https://github.com/librespeed/speedtest
$ cd speedtest
# Switch to `go` branch
$ git checkout go
Build
The following example will use 64-bit Linux as the operating system. Use the correct GOOS and GOARCH value for your
OS and system architecture.
# For Linux running on x86-64
$ GOOS=linux GOARCH=amd64 go build -ldflags "-w -s" -trimpath -o speedtest-backend main.go
# For Linux running on ARMv7
$ GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-w -s" -trimpath -o speedtest-backend main.go
# For Linux running on MIPSEL without hard floating point
$ GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-w -s" -trimpath -o speedtest-backend main.go
# For Windows running on x86-64
$ GOOS=windows GOARCH=amd64 go build -ldflags "-w -s" -trimpath -o speedtest-backend.exe main.go
If the resulting binary is too big for you, consider compressing it with upx (you need to install it with your package manager):
# Using compression level 9 is enough for most cases
$ upx -9 speedtest-backend
For an exhaustive list of GOOS, GOARCH, GOARM, GOMIPS, check out the official Go documentation.
Some additional info for cross compiling environment variables:
Supported platforms: https://github.com/golang/go/wiki/MinimumRequirements
Possible GOOS and GOARCH combinations: https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63 (Credit: @asukakenji)
GOARM: https://github.com/golang/go/wiki/GoArm
GOMIPS: https://github.com/golang/go/wiki/GoMips
Deploy
Copy the compiled binary speedtest-backend (or speedtest-backend.exe for Windows), settings.toml and the assets directory to the destination server/directory.
# Assume we will put the files under ~/speedtest
$ mkdir ~/speedtest
$ cp -r speedtest-backend settings.toml assets ~/speedtest
Configure
Configure your LibreSpeed backend by editing the settings.toml file. Comments on each option and their default (sane) values are already given in the included file.
# bind address
bind_address="127.0.0.1"
# backend listen port
listen_port=8989
# Server location, use zeroes to fetch from API automatically
server_lat=0
server_lng=0
# ipinfo.io API key, if applicable
ipinfo_api_key=""
# password for logging into statistics page
statistics_password="PASSWORD"
# redact IP addresses
redact_ip_addresses=false
# database type for statistics data, currently supports: bolt, mysql, postgresql
database_type="bolt"
database_hostname=""
database_name=""
database_username=""
database_password=""
# if you use `bolt` as database, set database_file to database file location
database_file="speedtest.db"
If you're planning to use PostgreSQL or MySQL as a telemetry result backend, make sure to create the corresponding database and import the schema file under database/postgresql or database/mysql directory.
For easier deployment, use BoltDB (bolt) should suffice.
Run
After making changes to settings.toml, run the compiled binary:
$ cd ~/speedtest
$ ./speedtest-backend
The web server should listen on port 8989 on localhost (127.0.0.1) by default. If you have changed bind_address or listen_port in the config, access the backend by the configured address:port.
Test
You can now access the backend via http://127.0.0.1:8989/example-singleServer-full.html (or the address and port you have defined in settings.toml.
If you plan to use another frontend example, make sure to add the server to the Speedtest object in JavaScript (inlined within the HTML examples), and put the resulting HTML into the assets directory.
If you want to access a default page via http://127.0.0.1:8989/ directly (without the long filename), simply rename the default page to index.html and put it into the assets directory.
Reverse proxy (Nginx, etc.)
If you plan to use a reverse proxy in front of the LibreSpeed backend, make sure you pass the real client IP to the backend (usually by X-Real-IP, X-Forwarded-For and friends), or else the client's IP on the speed test page would always be the address of your Nginx host.
Reverse proxy configuration example (Nginx)
upstream speedtest_backend {
server 127.0.0.1:8989;
keepalive 32;
}
server {
listen 80;
listen 443 ssl http2;
server_name <SERVER NAME HERE>;
ssl_certificate <SSL CERT HERE>;
ssl_certificate_key <SSL KEY HERE>;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Server $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
gzip off;
proxy_redirect off;
proxy_buffering off;
client_max_body_size 256M;
proxy_pass http://speedtest_backend/;
}
}