ssh root@ipaddress
enter password
sudo apt update
sudo apt upgrade
mkdir -p ~/.ssh && chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
cat ~/.ssh/id_rsa.pub
nano ~/.ssh/authorized_keys
Paste content from 4 here and save
-
adduser caleb
-
id caleb
-
usermod -aG sudo caleb
-
id caleb
-
ssh root@ipaddress
-
cd /home/caleb
-
mkdir .ssh
-
cd .ssh
-
touch authorized_keys
-
sudo nano authorized_keys (paste in the id_rsa_do.pub key, exit and log in as caleb)
ssh caleb@doserver
sudo chown -R caleb:caleb /home/caleb
chmod 700 /home/caleb/.ssh
-
sudo nano /etc/ssh/sshd_config
-
PermitRootLogin no
-
PasswordAuthentication no
-
sudo systemctl reload sshd
ssh-keygen -t rsa (id_rsa or whatever you want)
ssh-add /home/caleb/.ssh/id_rsa
eval ssh-agent -s
git clone [email protected]:your_git_repo
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install node 12.x
nvm list (lists node versions installed)
nvm use 12.x (selects a particular node version to be used)
node -v or npm -v (displays node version and npm version)
sudo npm i pm2 -g
pm2 start app (or whatever your file name)
pm2 start app.js
pm2 start npm --name "app name" -- start
pm2 start npm --name "dosh_ride" -- run start:prod
=> running custom scriptpm2 serve build/ 3000 --name "react-build" --spa
=> serving a react build
pm2 start api.js -i 4
pm2 start npm --name "app name" -- start -i 4
pm2 monitor
pm2 startup
pm2 unstartup
pm2 show app
pm2 status
pm2 restart app
pm2 stop app
pm2 logs (Show log stream)
pm2 flush (Clear logs)
sudo ufw enable
sudo ufw status
sudo ufw allow ssh (Port 22)
sudo ufw allow http (Port 80)
sudo ufw allow https (Port 443)
-
sudo apt install nginx
-
sudo nano /etc/nginx/sites-available/default
Add the following to the location part of the server block
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost:5000; #whatever port your app runs on
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;
}
sudo nginx -t
sudo service nginx restart
You should now be able to visit your IP with no port (port 80) and see your app. Now let's add a domain
In Digital Ocean, go to networking and add a domain
Add an A record for @ and for www to your droplet
Register and/or setup domain from registrar
I prefer Namecheap for domains. Please use this affiliate link if you are going to use them
https://namecheap.pxf.io/c/1299552/386170/5618
Choose "Custom nameservers" and add these 3
ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com
It may take a bit to propogate
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt install certbot
sudo apt-get install python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
sudo certbot renew --dry-run
Now visit https://yourdomain.com and you should see your Node app