Skip to content

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
openspeedtest committed Jun 22, 2023
1 parent 16dad00 commit 557df53
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 59 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ FROM nginxinc/nginx-unprivileged:stable-alpine

LABEL maintainer "OpenSpeedTest.com <support@OpenSpeedTest.com>"

<<<<<<< HEAD
ENV ENABLE_LETSENCRYPT=false
ENV DOMAIN_NAME=false
ENV USER_EMAIL=false
=======
>>>>>>> main
ENV CONFIG=/etc/nginx/conf.d/OpenSpeedTest-Server.conf

COPY /files/OpenSpeedTest-Server.conf ${CONFIG}
Expand Down
65 changes: 56 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,77 @@ If you need to run this image on a different port for `HTTP`, Eg: change to `80`
#### Container-Port for https is 3001
If you need to run this image on a different port for `HTTPS`, Eg: change to `443` = `-p 443:3001`

### How to use your own SSL Certificate?
### Setup Free LetsEncrypt SSL with Automatic Certificate Renewal
***Requirements***
- PUBLIC IPV4 and/or IPV6 address.
- A domain name that resolves to speed test server's IP address.
- Email ID

You can mount a folder with your own SSL certificate to this docker container by adding the following line to the above command.



````bash

-v /${PATH-TO-YOUR-OWN-SSL-CERTIFICATE}:/etc/ssl/
The following command will generate a Let's Encrypt certificate for your domain name and configure a cron job to automatically renew the certificate.

````
docker run -e ENABLE_LETSENCRYPT=True -e DOMAIN_NAME=speedtest.yourdomain.com -e USER_EMAIL=you@yourdomain.pro --restart=unless-stopped --name openspeedtest -d -p 80:3000 -p 443:3001 openspeedtest/latest
````
#### Or use docker-compose.yml
````
version: '3.3'
services:
speedtest:
environment:
- ENABLE_LETSENCRYPT=True
- DOMAIN_NAME=speedtest.yourdomain.com
- USER_EMAIL=you@yourdomain.pro
restart: unless-stopped
container_name: openspeedtest
ports:
- '80:3000'
- '443:3001'
image: openspeedtest/latest
````

### How to Use Your Own Secure Sockets Layer (SSL) Certificate, Self-Signed or Paid?
***Requirements***
- Folder with your Certificate, Self-Signed or Paid.
- Rename .cet file and .key file to `nginx.crt` & `nginx.key`

The folder needs to contain:
The folder needs to contain:

- `nginx.crt`

- `nginx.key`


````
sudo docker run --restart=unless-stopped --name openspeedtest -d -p 3000:3000 -p 3001:3001 openspeedtest/latest
````

To mount a folder with your own SSL certificate to this Docker container, append the following line to the above command:


````bash

-v /${PATH-TO-YOUR-OWN-SSL-CERTIFICATE}:/etc/ssl/

````

I am adding a folder with nginx.crt and nginx.key from my desktop by using the following command.

````bash

sudo docker run -v /Users/vishnu/Desktop/docker/:/etc/ssl/ --restart=unless-stopped --name openspeedtest -d -p 3000:3000 -p 3001:3001 openspeedtest/latest

````
#### Or use docker-compose.yml
````
version: '3.3'
services:
speedtest:
volumes:
- '/Users/vishnu/Desktop/docker/:/etc/ssl/'
restart: unless-stopped
container_name: openspeedtest
ports:
- '3000:3000'
- '3001:3001'
image: openspeedtest/latest
````
63 changes: 32 additions & 31 deletions files/OpenSpeedTest-Server.conf
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
#©CopyRight 2013-2023 by OpenSpeedTest.COM. All Rights Reserved.
#Official Website : https://OpenSpeedTest.COM | Email: support@openspeedtest.com
#Developed by : Vishnu | https://Vishnu.Pro | Email : me@vishnu.pro

#HTML5 Network Performance Estimation Tool -> [JS,XHR,SVG,HTML,CSS]
#Started in 2011 and Moved to OpenSpeedTest.COM, Dedicated Project/Domain Name in 2013.
#SpeedTest Script -> 2013 -> Beta | 2015 -> V1 | 2019 ->V2 | 2020 V2.1 | 2021 V2.12 | 2022 V2.5 & 2.5.3
#Self-Hosted OpenSpeedTest-Server (iFrame/Nginx) -> 2014. (Managed SelfHosted SpeedTesT Widget)
#OpenSpeedTest-Server (On-premises) (Fully SelfHosted Apps)
#[OpenSpeedTest-Server Docker Image] -> V1 2019 | V2 2020 | V2.1 2021 | V2.2 & 2.2.2 2022
#[Node.js/Electron JS OpenSpeedTest-Server Desktop Apps] -> 2020 V1 | 2021 V2 & V2.1 | 2.1.1 to 2.1.8 2022
#[Ionic Android and iOS OpenSpeedTest-Server Mobile Apps] V1.2 to 1.5 2022

#Download Now -> https://go.openspeedtest.com/Server

#Like this Project? Please Donate NOW & Keep us Alive -> https://go.openspeedtest.com/Donate

#Speed Test by OpenSpeedTest™️ is Free and Open-Source Software (FOSS) with MIT License.
#Read full license terms @ http://go.openspeedtest.com/License

#If you have any Questions, ideas or Comments Please Send it via -> https://go.openspeedtest.com/SendMessage

# SpeedTest by OpenSpeedTest™ is a Free and Open-Source Network Speed Test Software.
# Like this Project? Please Donate NOW & Keep us Alive -> https://go.openspeedtest.com/Donate
# Thank you for your support! we greatly appreciate your donation.
# Your contribution helps us continue to improve and maintain the tool for everyone to use.
# Official Website : https://OpenSpeedTest.com | Email: support@openspeedtest.com
# Developed by : Vishnu | https://Vishnu.Pro | Email : me@vishnu.pro

server {
server_name _ localhost;
Expand All @@ -39,7 +23,7 @@ server_name _ localhost;
ssl_session_timeout 10m;
root /usr/share/nginx/html/;
index index.html;
client_max_body_size 10000M;
client_max_body_size 35m;
error_page 405 =200 $uri;
access_log off;
gzip off;
Expand All @@ -55,6 +39,17 @@ server_name _ localhost;
open_file_cache_min_uses 2;
open_file_cache_errors off;

<<<<<<< HEAD
location ~ /\.well-known/acme-challenge/ {
allow all;
default_type "text/plain";
root /usr/share/nginx/html/;
try_files $uri =404;
break;
}

=======
>>>>>>> main
location / {

add_header 'Access-Control-Allow-Origin' "*" always;
Expand All @@ -72,16 +67,23 @@ server_name _ localhost;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With' always;
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
return 204;
return 200;
}
}

# IF and Only if you Enabled HTTP2 otherwise never enable the following
#location = /upload {
# HTTP2 will return 200 withot waiting for upload to complete. it's smart but we don't need that to happen here when testing upload speed on HTTP2.
#proxy_pass http://127.0.0.1:80/upload.bin;
#}
#HTTP2 & HTTP3 will not wait for the post body and return 200. We need to stop that behaviour.
#Otherwise, you will see abnormal upload speed. To fix this issue, Enable the following lines. (Only Applicable If you Enabled HTTP2 or HTTP3 in This Server.)

#HTTP2 & HTTP3 -> UPLOAD FIX -- START

#location = /upload {
#proxy_pass http://127.0.0.1:3000/dev-null;
#}
#location = /dev-null {
#return 200;
#}

#HTTP2 & HTTP3 -> UPLOAD FIX -- END

#Caching for Static Files,
location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|woff2|svg)$ {
Expand All @@ -104,5 +106,4 @@ location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|w
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
}

}
# Make this Nginx conf. Better? Send me you ideas -> https://go.openspeedtest.com/SendMessage
}
110 changes: 110 additions & 0 deletions files/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,114 @@ if [[ $? -ne 0 ]]; then
sed -i '/listen 300/d' ${CONFIG}
fi

<<<<<<< HEAD
Verify_TXT_path="/usr/share/nginx/html/Verify.txt"

if [ "$VERIFY_OWNERSHIP" ]; then
if [ -f "$Verify_TXT_path" ]; then
echo "Verify.txt Found!"
else
echo ${VERIFY_OWNERSHIP} > /usr/share/nginx/html/Verify.txt
echo "Verify.txt Created!"
fi
fi

if [ "$ALLOW_ONLY" ]; then

allow_only=${ALLOW_ONLY}

IFS=';' domains=$(echo "$allow_only" | tr ';' '\n')

map_config="map \$http_origin \$allowed_origin {
default 0;
"
while IFS= read -r line; do
escaped_domain=$(echo "$line" | sed 's/\./\\./g')
map_config="$map_config \"~^https?://(www\.)?($escaped_domain)\$\" 1;
"
done < <(printf '%s\n' "$domains")

map_config="$map_config}"

nginx_conf_path="/etc/nginx/nginx.conf"
pattern="map \$http_origin \$allowed_origin {"
nginx_block="if (\$allowed_origin = 0) { return 444; }"

if grep -q "$pattern" "$nginx_conf_path"; then
echo "Map config found! nginx.conf not modified"
else
while IFS= read -r line; do
sed -i '/^\s*http\s*{/ {
:a;
N;
/\s*}\s*$/!ba;
s|\(}\)|'"$line"'\n\1|
}' "$nginx_conf_path"
done < <(printf '%s\n' "$map_config")
if [ $? -eq 0 ]; then
echo "Map config added to nginx.conf"
if grep -q "$nginx_block" "$CONFIG"; then
echo "Block Config found! OpenSpeedTest-Server.conf not modified"
else
echo "Adding Block Config to OpenSpeedTest-Server.conf"
sed -i '/location \/ {/ {
a\
'"$nginx_block"'
}' "$CONFIG"

sed -i '/location ~\* \^.+\\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|woff2|svg)\$ {/ {
a\
'"$nginx_block"'
}' "$CONFIG"
if [ $? -eq 0 ]; then
echo "Added Block to OpenSpeedTest-Server.conf"
else
echo "Failed to Add Block to OpenSpeedTest-Server.conf"
fi
fi


else
echo "Failed to add map config to nginx.conf"
fi
fi

fi


if [ "$DOMAIN_NAME" ]; then
sed -i "/\bYOURDOMAIN\b/c\ server_name _ localhost ${DOMAIN_NAME};" "${CONFIG}"
fi

nginx -g 'daemon off;' & sleep 5

if [ "$ENABLE_LETSENCRYPT" = True ] && [ "$DOMAIN_NAME" ] && [ "$USER_EMAIL" ]; then

fullchain_path="/var/log/letsencrypt/live/${DOMAIN_NAME}/fullchain.pem"

certbot certonly -n --webroot --webroot-path /usr/share/nginx/html --no-redirect --agree-tos --email "$USER_EMAIL" -d "$DOMAIN_NAME" --config-dir /var/log/letsencrypt/ --work-dir /var/log/letsencrypt/work --logs-dir /var/log/letsencrypt/log

if [ $? -eq 0 ]; then

if [ -f "$fullchain_path" ]; then
sed -i "/\bssl_certificate\b/c\ssl_certificate \/var\/log\/letsencrypt\/live\/${DOMAIN_NAME}\/fullchain.pem;" "${CONFIG}"
sed -i "/\bssl_certificate_key\b/c\ssl_certificate_key \/var\/log\/letsencrypt\/live\/${DOMAIN_NAME}\/privkey.pem;" "${CONFIG}"
nginx -s reload
echo "Let's Encrypt certificate obtained successfully."
random_minute=$(shuf -i 0-59 -n 1)
random_hour=$(shuf -i 0-23 -n 1)
echo "$random_minute $random_hour * * * /renew.sh > /proc/1/fd/1 2>&1" > /etc/crontabs/nginx
else
echo "letsencrypt Certificates Not Found!"
fi
else
echo "Failed to obtain Let's Encrypt certificate."
fi
fi

crond -b -l 5

tail -f /dev/null
=======
exec nginx -g 'daemon off;'
>>>>>>> main
20 changes: 1 addition & 19 deletions files/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
# ©CopyRight 2013-2021 by OpenSpeedTest.COM. All Rights Reserved.
# Website : OpenSpeedTest.COM | email: support@openspeedtest.com
# Developed by : Vishnu | https://vishnu.pro | email : me@vishnu.pro

# HTML5 Network Performance Estimation Tool -> [JS,XHR,SVG,HTML,CSS]
# Started in 2011 and Moved to OpenSpeedTest.COM Dedicated Project/Domain Name in 2013.
# SpeedTest Script -> 2013 -> Beta | 2015 -> V1 | 2019 ->V2 | 2020 V2.1 | 2021 V2.12.

# Slef-Hosted OpenSpeedTest-Server (iFrame/Nginx) -> 2015.
# OpenSpeedTest-Server (On-premises) -> 2020 V1 | 2021 V2 & V2.1 [Node.js/Electron JS, Docker]
# Download -> https://go.openspeedtest.com/Server

# Like this Project? Please Donate NOW & Keep us Alive -> https://go.openspeedtest.com/Donate

# Share — copy and redistribute the material in any medium or format for any purpose, even commercially.
# Read full license terms @ https://go.openspeedtest.com/License

# If you have any Questions or Comments Please Send it via -> https://go.openspeedtest.com/SendMessage
worker_processes auto;
#worker_rlimit_nofile 100000;
worker_rlimit_nofile 100000;
events {
worker_connections 2048;
multi_accept on;
Expand Down
20 changes: 20 additions & 0 deletions files/renew.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh


fullchain_path="/var/log/letsencrypt/live/${DOMAIN_NAME}/fullchain.pem"

if [ "$ENABLE_LETSENCRYPT" = True ] && [ "$DOMAIN_NAME" ] && [ "$USER_EMAIL" ]; then

certbot renew --force-renewal
if [ $? -eq 0 ]; then
echo "certbot renew --force-renewal Executed."
if [ -f "$fullchain_path" ]; then
nginx -s reload
else
echo "letsencrypt Certificates Not Found!"
fi
else
echo "certbot renew --force-renewal Failed."
fi

fi

0 comments on commit 557df53

Please sign in to comment.