Server Setup
This document outlines how we set up our remote servers for running projects.
1. Provision a Server
We use DigitalOcean as our provider. Regardless of your choice, provision a new VPS using the latest Ubunutu LTS version. Add your ssh
key AND Naomi’s ssh
key in the setup process.
2. Set Up User
You should never run applications on root. SSH into the new VPS to prepare your user.
2.1. Creating the User
You’ll need to set a password for the root
account first.
Once you have set a password, ensure that you have provided it to Naomi to store in the vault.
Create an nhcarrigan
user for our organisation.
Set a different password, and provide that to Naomi as well. For all of the user information, use the default blank values.
Add the new user to the sudoers file.
Then sync the SSH keys so we can authenticate as that user.
While you are there, set the timezone for the server to our business’ local timezone.
3. Preparing For Web Requests
To prepare the server to receive web requests, you’ll need to follow a few steps.
3.1. SSL Certificate
We use LetsEncrypt to provision our SSL certificates. If it is not installed, install it with:
Then link the snap to our usr
directory.
Generate a certificate with:
And allow applications to read it:
When you need to renew the certificate:
3.2. NGINX
All requests should be routed through NGINX. At no point should an application run directly on ports 80 or 443.
Install NGINX:
Edit the configuration file:
Use this template to set up a reverse proxy on the standard HTTPS port 443:
Validate that the config is correct with:
If so, restart NGINX to apply the changes:
4. Securing the Server
We have a minimum level of security that is required on ALL of our servers. This section should not be treated as the best effort, but as the minimal requirements to comply with our policies.
4.1. Firewall
We use ufw
as our firewall. First, enable the SSH port.
Then, allow the standard HTTPS port and deny the standard HTTP port.
Enable the firewall. You may get dropped from the SSH connection.
4.2. Fail2Ban
We also use Fail2Ban to block IP addresses which fail to make requests too often.
Install the tool:
Configure the NGINX jail in /etc/fail2ban/jail.d/nginx-auth.conf
:
Configure the NGINX filter in /etc/fail2ban/filter.d/nginx-auth.conf
:
Because we use Cloudflare, you’ll need to grab the original IP for all requests. Start by creating a file to store Cloudflare’s IPs.
Then create your script:
Make it executable and run it:
If it runs as expected, set it up to run on a CRON.
Then, update the /etc/nginx/nginx.conf
to use all of this new logic. This goes at the end of your http
directive block.
Confirm the NGINX configuration is correct:
Then restart everything.
To view banned IPs:
And to unban them:
5. Running a Project
Now you are ready to start running the project.
5.1. Node.js
Most of our projects will run on Node. For a new machine, you’ll need to set that up.
We use nvm
to manage Node versions. Fetch and run the install script:
The script will automatically update the .bashrc
file to load nvm
into the PATH. Reload that:
Install the long-term support Node version.
This should automatically set it as the default. When updating, be sure to remove any older versions!
Finally, install pnpm
as the package manager.
5.2. PM2
All of our processes run with PM2 to allow for monitoring and auto-restarts. You’ll need to install it.
To start a project, use this template:
Then run pm2 save
to save the application list.