lore is an online community forum built with a Vite frontend (lore-frontend
) and a NestJS backend (lore-backend
).
You'll find recipes below to help you deploy, update, and maintain the site.
Environment: AWS Lightsail instance (Amazon Linux 2023)
# refresh package list
sudo dnf upgrade
# install Node.js LTS (20.x) + build tools
sudo dnf install nodejs20 gcc-c++ make
# verify
node -v # v20.*
npm -v
sudo dnf install git
sudo mkdir -p /srv/sites
cd /srv/sites
# give yourself ownership and nginx read‑only access
sudo chown ec2-user:nginx /srv/sites
sudo chmod 2750 /srv/sites
git clone https://github.com/astro2049/Lore.git
cd Lore
cd lore-frontend
# supply environment variables / .env
cp .env.example .env.local
nano .env.local
npm install
npm run build
cd lore-backend
# supply environment variables / .env
cp .env.example .env
nano .env
npm install
npm run build
# create schema
npx typeorm-ts-node-commonjs migration:run -d src/data-source.ts
# start the app
npm run start:prod
# or, in background
nohup npm run start:prod > app.log 2>&1 &
echo $! > app.pid
part 1. install and start Nginx
sudo dnf install nginx
# verify
nginx -v
# enable Nginx to start on boot (enable) and start it right now (--now)
sudo systemctl enable --now nginx
# verify
sudo systemctl status nginx
part 2. supply the configs
sudo nano /etc/nginx/conf.d/lore.conf
lore.conf
server {
listen 80; # HTTP port
server_name yourdomain.com; # or your Lightsail (static) IP
# Disable logs
access_log off;
error_log /dev/null crit;
# Vite app
root /srv/sites/Lore/lore-frontend/dist;
index index.html;
# Serve static assets (js, css, images, fonts, etc.) with long cache
location ~* \.(?:js|mjs|css|woff2?|ttf|eot|svg|png|jpe?g|gif|ico|webp)$ {
try_files $uri =404;
access_log off;
expires 30d;
add_header Cache-Control "public, immutable";
}
# SPA fallback
location / {
try_files $uri /index.html;
}
# NestJS app, reverse proxy
location /api/ {
proxy_pass http://127.0.0.1:3000/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
part 3. verify syntax and reload configs
# syntax check
sudo nginx -t
# reload configs
sudo systemctl reload nginx
# install Certbot & Nginx plugin
sudo dnf install certbot python3-certbot-nginx
# get and install your certificates
sudo certbot --nginx -d yourdomain.com
# test renewal
sudo certbot renew --dry-run
cd into the repo
# lore
cd /srv/sites/Lore
# Vite frontend
cd /srv/sites/Lore/lore-frontend
# NestJS backend
cd /srv/sites/Lore/lore-backend
start the app
# option 1: in foreground
npm run start:prod
# option 2: in background
# redirect all output (stdout and stderr) to app.log
nohup npm run start:prod > app.log 2>&1 & disown
# save the PID to app.pid (useful for stopping the process later)
echo $! > app.pid
stop the app
kill $(cat app.pid)
# or
kill $(lsof -iTCP:3000 -sTCP:LISTEN -t)
verify syntax and reload configs
# syntax check
sudo nginx -t
# reload configs
sudo systemctl reload nginx
install the HTTPS certificate
sudo certbot install --cert-name yourdomain.com
Environment: AWS Lightsail MySQL Database
npx typeorm-ts-node-commonjs migration:generate src/migrations/<MigrationName> -d src/data-source.ts
npx typeorm-ts-node-commonjs migration:run -d src/data-source.ts