Production

Keywords

Production

Resources

Resources

In these videos I am going to set up a web socket application at Digital Ocean. Of course you can choose other providers but since you got free virtual hosting (for a while) through the github student developer pack we are going to use this provider through out these articles and demos. To follow along please create a account at Digital Ocean and use the promotion code from GitHub.

Getting a Ubuntu web server up and running

In the first step we start by creating a Ubuntu server. Digital Oceans have different kind of droplets (a virtual machine in the cloud), some with just the OS and some with pre-installed stuff. We have written an article that uses the bare OS droplets. It will guide you through how to create a droplet with Ubuntu 16.04 and how to secure it a bit (update with fixes, create a non-root user and installing a simple firewall). You find the article here: https://github.com/CS-LNU-Learning-Objects/the-node-platform-production/blob/master/creating-a-server.md

We also have a older video that uses a pre-installed droplet. Since the demo was recorded Digital Ocean has changed the MEAN machine so you should probably choose the NodeJS-droplet instead. If you need mongoDB you can follow the guide to install it: https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04. The video don´t include the security stuff the article above mention so please if you watch it have this in mind.

Getting our code up to the server

In the next part we set up the server to be able to listen for git pushes. That way we can push our code to the production server the same way we push it to GitHub. In the video much is taken from the article found here: https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps

OBS! In the video I'm logged in with the root account (which is bad practice). If you follow the article above and created a non-root-user you may get "permission denied" when using most of the commands on the server. To execute the command as a privileged user we must add "sudo" in-front of the command:

sudo mkdir /var/repo

To get the push workflow to work (if we using our non-root-user) we also must make the directories on the server writable for this user. We can du this by changing the owner of the directories we create in the video:

sudo chown -R <your user> /var/repo
sudo chown -R <your user> /var/www

Using a process manager

Next it is time to install a process manager that help us with running our node application.

Adding HTTPS to the server

A demo movie about creating self-signed HTTPS certificates (same as in the web security lecture) and running your application with HTTPS. Later on (in the last video) your Nginx will be handle the HTTPS.

Putting a reversed proxy in front of the application

In the last video we sets up a Nginx web server as an reversed proxy. We also let the Nginx handle all request to static files hand taking care of the encryption and decryption needed for running HTTPS. To get to the gist talked about in the video follow: https://gist.github.com/thajo/d5db8e679c1237dfdb76. This configuration proxy the requests to http://localhost:3000 meaning that your node application will listen on http-requests on port 3000. If you using cookies that must have a https connection remember to set the "trust proxy" flag in your express configuration

Welcome to CoursePress

en utav Linnéuniversitets lärplattformar. Som inloggad student kan du kommunicera, hålla koll på dina kurser och mycket mer. Du som är gäst kan nå de flesta kurser och dess innehåll utan att logga in.

Läs mer lärplattformar vid Linnéuniversitetet

Student account

To log in you need a student account at Linnaeus University.

Read more about collecting your account

Log in LNU