How to setup a Node.js + MongoDB environment with PM2 and Let's Encrypt
ssh root@your_server_ip
sudo apt-get update
sudo apt-get upgrade
* adduser braitsch
* usermod -aG sudo braitsch
rsync --archive --chown=braitsch:braitsch ~/.ssh /home/braitsch
ssh braitsch@your_server_ip
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.bashrc
nvm list-remote
nvm install --lts
node -v
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod
sudo apt update
sudo apt install nginx
sudo nano /etc/nginx/sites-available/my_domain
server {
server_name my_domain.org www.my_domain.org;
root /home/braitsch/site/server; # required to serve static images
location / {
proxy_pass http://localhost:8081; #nuxt app
proxy_http_version 1.1;
proxy_set_header Host $host;
}
location /api {
proxy_pass http://localhost:8080; #express app
proxy_http_version 1.1;
proxy_set_header Host $host;
client_body_buffer_size 1M; #required for image uploads
client_max_body_size 100M; #required for image uploads
}
location /static {
proxy_pass http://localhost:8080;
try_files $uri $uri/ =404; # static asset directory
}
}
sudo ln -s /etc/nginx/sites-available/my_domain /etc/nginx/sites-enabled/
sudo nano /etc/nginx/nginx.conf
http {
server_names_hash_bucket_size 64; # <- uncomment this line
}
sudo nginx -t
sudo systemctl restart nginx
sudo ufw enable
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw status
sudo snap install core; sudo snap refresh core
sudo apt remove certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d my_domain.com -d www.my_domain.com
sudo systemctl status snap.certbot.renew.service
sudo certbot renew --dry-run
npm install pm2@latest -g
sudo timedatectl set-timezone America/Los_Angeles