Get yourself a fresh instance of Ubuntu!
This tutorial is suited for aws instances but may work for other providers too.
sudo apt install nginx
sudo vim /etc/nginx/sites-available/mycircle
Configure your file as mentioned below. By default, instance recieves web requests on port 80, so we want to redirect
our frontend (/) to port 3001 (my choosing) and the backend (/api) to port 5000 (also my choosing).
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name mycircle.live, www.mycircle.live;
listen 443 ssl; # managed by Certbot
# RSA certificate
ssl_certificate /etc/letsencrypt/live/mycircle.live/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mycircle.live/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
# Redirect non-https traffic to https
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
location / {
proxy_pass https://localhost:3001;
}
location /api {
proxy_pass https://localhost:5000;
}
}
Finalise config as below.
sudo ln -s /etc/nginx/sites-available/mycircle /etc/nginx/sites-enabled/mycircle
sudo service nginx reload
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt install npm
sudo su
Need to get the root key
ssh-keygen -t ed25519 -C "[email protected]"
cat /home/ubuntu/.ssh/id_ed25519.pub
Copy key to github
vim /etc/ssh/ssh_config
PubkeyAuthentication yes
PubkeyAcceptedKeyTypes=+ssh-rsa
vim ~/.ssh/config
Host *
IgnoreUnknown UseKeychain
UseKeychain yes
AddKeysToAgent yes
IdentityFile /root/.ssh/id_ed25519
sudo systemctl restart sshd.service
cd /var/www/html
git clone [email protected]:[name]/[repo].git
npm install pm2 -g
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt update
sudo apt install -y mongodb-org
echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.listsudo apt-get update
sudo apt-get update
sudo apt-get install libssl1.1
sudo apt install -y mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
sudo systemctl status certbot.timer
sudo certbot renew --dry-run
Now using the current project structure and deploy script, your app should be running on your next deploy.