In my previous post I gave a walkthrough of setting up your own $4 server. Let’s take things to the next level by upgrading our little VPS to host multiple sites using Nginx.
1. Install Nginx
Remote ssh into your droplet
Go to nvm and run the install & update script
e.g. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
Run
source .bashrc
to getnvm
workingInstall node using
nvm install --lts
Install Nginx using
apt-get install nginx
2. Update Nginx Config
Installing Nginx created a new folder /etc/nginx/
cd /etc/nginx/
Create a file to contain your site configuration using
touch sites-available <project-name>
Add the following to your file
/etc/nginx/sites-available/<project-name>
server {
listen 80;
server_name IP_ADDR;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Note: Update IP_ADDR
with your ip address or domain name and update proxy_pass
with correct internal port
Create a symbolic link using
ln -s /etc/nginx/sites-available/<project-name> /etc/nginx/sites-enabled/<project-name>
Check that everything is configured correct with
nginx -t
Restart nginx using
service nginx restart
3. Enable Firewall for Nginx
- See apps using
ufw app list
- Allow OpenSSH and Nginx
ufw allow OpenSSH
ufw allow "Nginx Full"
- Enable
ufw enable
- See new rules
ufw status verbose
- This shows the only ports available