Get a machine

This is demoed is the stream. I use DigitalOcean, but any host that gives you a virtual machine will work for these instructions. AWS, Azure, and Google Cloud Platform have a free year of service.

The first thing you do when you get this machine should be to set up a user. I will create the cws user with adduser. Note that the password will not show as you enter it. Just type and press enter.

# adduser cws
Adding user `cws' ...
Adding new group `cws' (1000) ...
Adding new user `cws' (1000) with group `cws' ...
Creating home directory `/home/cws' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for cws
Enter the new value, or press ENTER for the default
	Full Name []:
	Room Number []:
	Work Phone []:
	Home Phone []:
	Other []:
Is the information correct? [Y/n] y

You should log out of root and log in as that user.

Install dependencies

Web server

I will use Caddy for this demo. They have fine install instructions. I recommend reading the Caddyfile quick-start as well.

Mongo

If using an Ubuntu/Debian host, sudo apt install mongodb-server

Node

To get the latest version of node, ceck out the Nodesource distribution instructions for debian distributions.

Set up DNS

This is demoed in the stream. The details vary, but set up a new A record with whatever IP you have from getting a server.

Transfer the project to the server

I tend to use scp to transfer files to the server. You could use some other sftp client as well. The -r (recursive) flag is useful to ensure that you can transfer directories.

$ scp -r courseware-assignments cws@courseware.chrissexton.org:

Note the : at the end of the SSH server identification. This indicates we are transferring to the "default" directory of the cws user. We could specify by putting a path after that colon. Without it, you will not transfer any files.

Set up the webserver

I use Caddy because it’s simple and allows me to set up automatic HTTPS sites without much work.

For my site, hosted at courseware.chrissexton.org, the configuration looks like this:

courseware.chrissexton.org (1)

root build (2)
file_server

reverse_proxy /v1/* 127.0.0.1:6061 (3)

handle_errors {
	rewrite * /index.html
	root build  (2)
	file_server
}
1 Change this to the DNS name of your server
2 Change build to the path of your front-end files
3 Change this port to whatever port your back-end runs on

Angular has documentation for Other webservers.

Secure the webserver

  • Disable root logins!

  • Ensure a firewall is running (ubuntu comes with ufw and it’s nice)

  • Ensure no extra services are running

  • Ensure your backend application only responds to 127.0.0.1

Using GitHub Pages

You can use GitHub to host sites as well, but they cannot (easily) rely on a backend. To do this, follow the directions of github for sites and commit your built site to your repository. Copy the index.html file to 404.html so that node routing will work.