How to install

How to install CDN system

We offer free install on Shared Hosting when hosting with Hosturly

Install on Ubuntu 20.04

  1. Run sudo apt update
  2. Install python3 sudo apt install python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools
  3. Install python3 venv sudo apt install python3-venv
  4. Create a directory to hold the files, in this example ours is in home/username/cdn
  5. CD into the created directory, for example ours would be cd home/username/cdn
  6. Create the venv using python3 -m venv cdn_app
  7. Activate the venv using source cdn_app/bin/activate
  8. Install starter packages pip install wheel, pip insall uwsgi flask
  9. Place files in the directory (In the example it is home/username/cdn)
  10. Install app requirements once files are placed using pip install -r requirements.txt
  11. Allow port 5000 on your firewall using sudo ufw allow 5000
  12. Change the config values in config/config.yaml (the discord callback should be set to https://yourdomain.net/callback)
  13. Run the site to see if it comes online using python run.py (Any errors saying cannot find "module" cant be fixed by running pip install module)
  14. Navigate to your-server-ip:5000 and the site should be online, if so ctrl+c in the console
  15. Drag cdn.ini and wsgi.py out of the vps-only folder
  16. Run uwsgi and see if the site comes online, run uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:site
  17. Deactivate the venv using deactivate
  18. Open source.sql and change line 46 and 47
  19. Login to MYSQL using mysql -u username -p
  20. Add the tables to the database using source home/username/cdn/source.sql

Create a service

  1. Create the service file using sudo nano /etc/systemd/system/cdn.service

  2. Add the following text to the file, make sure to change directorys to match yours

    [Unit]
    Description=uWSGI instance to serve the CDN
    After=network.target

    [Service]
    User=username
    Group=www-data
    WorkingDirectory=/home/username/cdn
    Environment="PATH=/home/username/cdn/cdn_app/bin"
    ExecStart=/home/username/cdn/cdn_app/bin/uwsgi --ini cdn.ini

    [Install] WantedBy=multi-user.target

  3. Start the service using sudo systemctl start cdn

  4. Make sure the service started using sudo systemctl status cdn, if should say Active: active

  5. Allow the service to run automatically using sudo systemctl enable cdn


Allow Nginx to handle requests

  1. Create the config file using sudo nano /etc/nginx/sites-available/cdn
  2. Add the below lines to the file, changing domain and file path

    server {
    listen 80;
    server_name your_domain www.your_domain;

    location / {
    include uwsgi_params;
    uwsgi_pass unix:/home/username/cdn/cdn_site.sock;
    }
    }

  3. Link the config file to enable it using sudo ln -s /etc/nginx/sites-available/cdn /etc/nginx/sites-enabled
  4. Unlink the default config file using sudo unlink /etc/nginx/sites-enabled/default
  5. Test the config using sudo nginx -t
  6. Restart nginx sudo systemctl restart nginx
  7. Allow full nginx access on the ufw sudo ufw allow 'Nginx Full
  8. Navigate to the domain and the site should be up

Getting a SSL

  1. Install cerbot sudo apt install certbot python3-certbot-nginx
  2. Allow it to issue a SSL sudo certbot --nginx -d your_domain -d www.your_domain