Digipad - omartek/linux_variePerLaboratorio GitHub Wiki

Installato su VPS Ubuntu 22.04.2 - 15/04/2023

Table of contents generated with markdown-toc

Installazione Redis

Dalla guida ufficile https://redis.io/docs/getting-started/installation/install-redis-on-linux/

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

sudo apt-get update
sudo apt-get install redis

sudo systemctl enable redis.service

Installazione Nodejs e pm2

Dal repo ufficiale https://github.com/nodesource/distributions

curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

sudo npm install pm2 -g

Installazione e avvio Digipad

Scaricando dal repo https://codeberg.org/ladigitale/digipad

wget https://codeberg.org/ladigitale/digipad/archive/1.0.4.tar.gz
tar -xf 1.0.4.tar.gz 
cd digipad/
nano .env

Questo il contenuto del file .env

DOMAIN="https://digipad.scuolabit.it"
HOST="91.205.174.47"
PORT="3000"
DB_HOST="127.0.0.1"
DB_PWD=""
DB_PORT="6379"
SESSION_KEY="1234"
SESSION_DURATION="3600000"
ETHERPAD="91.205.174.47:82"
ETHERPAD_API_KEY="FIND_IN_ETHERPAD_FILES" # in app/docker root inside APIKEY.txt
UPLOAD_LIMIT="3"
UPLOAD_FILE_TYPES=".jpg, .jpeg, .png, .gif, .mp4, .m4v, .mp3, .m4a, .ogg,.wav,.pdf,.ppt,.pptx,.odp,.doc,.docx,.odt,.ods,.odg,.xls,.xlsx"
PAD_LIMIT="100"
CRON_TASK_DATE=""
ADMIN_PASSWORD="CHANGEME"
EMAIL_HOST=""
EMAIL_ADDRESS=""
EMAIL_PASSWORD=""
EMAIL_PORT=""
EMAIL_SECURE=""
MATOMO=""
MATOMO_SITE_ID=""
NFS_PAD_NUMBER=""
NFS_FOLDER=""
NFS2_PAD_NUMBER=""
NFS2_FOLDER=""
AUTORIZED_DOMAINS="*"

Avviare l'installazione delle dipendenze, la build e l'esecuzione in background

npm install
npm run build
pm2 start

Aprendo la porta 3000 il servizio è disponibile all'indirizzo http://IP:3000 ma senza funzionare correttamente

sudo ufw allow 3000

Installazione e configurazione Nginx come proxy con Lets'Encrypt

Se il server non dispone già di web server installare Nginx e Certbot per automatizzare la gestione dei certificati con Letsencrypt

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-22-04#step-5-%E2%80%93-setting-up-server-blocks-(recommended)

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-22-04#step-1-installing-certbot

Nginx: server block e creazione certificati

Creare il server block per il servizio

sudo nano /etc/nginx/sites-available/digipad.scuolabit.it

questo il contenuto del file (come indicato qui https://blog.tericcabrel.com/deploy-a-node-js-application-with-pm2-and-nginx/ e con l'aggiunta di quanto indicato qui https://stackoverflow.com/questions/41381444/websocket-connection-failed-error-during-websocket-handshake-unexpected-respon)

server {
    server_name  node.tericcabrel.com;
    index index.html index.htm;
    access_log /var/log/nginx/nodeapp.log;
    error_log  /var/log/nginx/nodeapp-error.log error;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://91.205.174.47:3000; # usare localhost o 127.0.0.1?
        proxy_redirect off;
        # enable WebSockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

    }
}

Creare il link simbolico e generare i certificato con certbot

sudo ln -s /etc/nginx/sites-available/digipad.scuolabit.it /etc/nginx/sites-enabled/digipad.scuolabit.it
sudo certbot --nginx -d digipad.scuolabit.it
sudo nginx -t # for testing
sudo systemctl reload nginx.service

Controllare che il firewall abbia i permessi sufficienti a far funzionare tutto:

sudo ufw allow 'Nginx Full'
sudo ufw status

Integrazione di Etherpad per documenti collaborativi

Avviare un Etherpad con docker https://github.com/omartek/linux_variePerLaboratorio/wiki/Linux-Docker#etherpad

Come indicato nella documentazione ufficiale qui https://etherpad.org/doc/v1.8.16/#index_http-api

Authentication Authentication works via a token that is sent with each request as a post parameter. There is a single token per Etherpad deployment. This token will be random string, generated by Etherpad at the first start. It will be saved in APIKEY.txt in the root folder of Etherpad. Only Etherpad and the requesting application knows this key. Token management will not be exposed through this API.

Creare il server block per Nginx

server{
    server_name etherpad.scuolabit.it;
    access_log /var/log/nginx/st-access.log;
    error_log /var/log/nginx/st-error.log debug;

    location / {
    proxy_pass http://localhost:82;
    }
}

Aggiornare Nginx, creare il certificato e riavviare

sudo ln -s /etc/nginx/sites-available/etherpad.scuolabit.it /etc/nginx/sites-enabled/etherpad.scuolabit.it
sudo certbot --nginx -d etherpad.scuolabit.it
sudo nginx -t # for testing
sudo systemctl reload nginx.service
⚠️ **GitHub.com Fallback** ⚠️