Here we describe how to host your Jupyter Book project on a TU Delft webserver, including requesting the server and setting it up as a webserver.
Requesting a TU Delft (web)server¶
Talk to your departmentâs IT support to ask for support in setting up a virtual TUD linux server (Faculty Managed Servers). If agreed upon, you can request a FMS, specifically a linux (Ubuntu) server with ports 22 (ssh), 80 (http) and 443 (https) open. Faculty domain specific servers are preferred (e.g. somesite
When approved and made available, an email is sent with the first details:
Setup TU Delft webserver¶
Use putty to connect to the server via ssh. HostName is given under Step A (connect to linux-bastion). Click
Open.
Click accept, allowing the computer to connect to the server.
Login with your netID (without @tudelft.nl)
Use the information under Step B (use SSH Key-Based Authentication). (
ssh <servername>.tudelft.nl)
You are now logged in to the server.
We first install the webserver (apache). Run
sudo apt install apache2.We can check whether it successfully installed by going to the serverâs IP address in a web browser. You should see the default apache page. Or confirm by running
sudo systemctl status apache2and checking whether the service is active (running).Make a second user
sudo adduser web, make a password (14 characters) for this user.
Everything that is in home/web/ will be visible on the webserver. You can use cd /home/web to navigate to this directory.
Assign your self the web user:
sudo -u web bash -and navigate to home/web.Make a directory call
.sshby runningmkdir .sshand navigate to it.Create an ssh key by running
ssh-keygen. Do not use a passphrase. This a vulnerability but is necessary for the webserver to be able to pull from GitHub without manual input.
Two keys are generated: id_rsa (private key) and id_rsa.pub (public key). The public key needs to be copied to an authorized_keys file.
Run
cp id_rsa.pub authorized_keysto do this. You will need the private key later to add it to GitHub/GitLab.
We are now ready with setting up the server, but need to secure it.
Run
sudo -ito open become a superuser. We need to install a firewall which can be done by runningapt install ufw.We need to allow ssh, http and https traffic through the firewall. This can be done by running
ufw allow ssh,ufw allow httpandufw allow https. Enable the firewall by runningufw enable. You can check the status of the firewall by runningufw status.Run
apt install fail2banto install fail2ban, which is a software that protects against brute-force attacks. It works by monitoring the log files for failed login attempts and banning the IP address after a certain number of failed attempts. You can check the status of fail2ban by runningsystemctl status fail2ban.
If you decided to maintain your server yourself, you will need to regularly check for updates and security patches. This can be done by running apt update and apt upgrade. You can also set up automatic updates by running apt install unattended-upgrades and configuring it to your needs.
Change start dir¶
Apache has set the home folder to var/www where we want it to be home/web. Using the terminal:
Run
sudo nano /etc/apache2/sites-available/000-default.confChange
DocumentRoot /var/www/htmltoDocumentRoot /home/web.Add:
<Directory /home/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>Save the changes
Ctrl+O, Enter, Ctrl+Xand runsudo systemctl restart apache2Follow steps 2-4 after:
sudo nano /etc/apache2/sites-available/default-ssl.confRun
sudo a2ensite default-ssl.conf
sudo a2enmod ssl
sudo systemctl reload apache2Check whether
Syntax OKis shown after running:sudo apache2ctl configtest, else:sudo systemctl restart apache2
Request SSL-certificate¶
We need to request an SSL-certificate:
sudo apt update
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d <server>and test:
sudo apache2ctl configtest
sudo systemctl reload apache2Useful linux commands¶
| command | |
|---|---|
ls | list files in the current directory |
ls -a | list all files (hidden) in the current directory |
ls -l | list files in long format (permissions, owner, size, date) |
cd | change directory |
cd ~ | change to home directory |
pwd | print working directory |
q | quit |
exit | exit the terminal / logout |
sudo | run a command with superuser privileges |
sudo -s | open a root shell |
cat | concatenate and display file content |
reboot | reboot the server |
To host your website on a university webserver youâll need:
a gitlab repo with CI/CD script (below)
a (linux) webserver
a runner
an SSH key
How to set up a
:caption: .gitlab-ci.yml for TU server deployment
stages:
- deploy
image: python:3.11-slim
variables:
SSH_COMMAND: 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes'
LOCAL_BUILD_DIR: "_build/html"
HOST: "127.0.0.1" # prevents running local host resulting in an error
BASE_URL: "" # specify the base url, e.g. the folder from root
before_script:
- apt-get update
- apt-get install -y --no-install-recommends curl rsync openssh-client git
# Node.js
- curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
- apt-get install -y --no-install-recommends nodejs
- node --version
- npm --version
# Python deps
- python -m pip install --upgrade pip
- pip install mystmd
- pip install -r requirements.txt
# SSH key laden
- eval "$(ssh-agent -s)"
- chmod 400 "$WEBSITE_UPLOAD_KEY"
- ssh-add "$WEBSITE_UPLOAD_KEY"
deploy:
stage: deploy
script:
# builds the book
- myst build --html
# syncs with the server
- rsync -ravz "${LOCAL_BUILD_DIR}/" -e "${SSH_COMMAND} -i ${WEBSITE_UPLOAD_KEY}" "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/"