Gatsby builds React static sites. On a VPS you compile once and serve HTML/JS/CSS with Nginx.
Steps
Ensure Node.js LTS and the Gatsby CLI:
node -v || (curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt install -y nodejs)sudo npm install -g gatsby-cligatsby --versionScaffold the project and run a production build:
cd ~ && npx gatsby new my-gatsbycd ~/my-gatsbynpm run buildPublish public/ with Nginx:
sudo mkdir -p /var/www/my-gatsbysudo rsync -a ~/my-gatsby/public/ /var/www/my-gatsby/sudo tee /etc/nginx/sites-available/my-gatsby >/dev/null <<'EOF'server { listen 80; server_name example.com; root /var/www/my-gatsby; index index.html; try_files $uri $uri/ /index.html;}EOFsudo ln -sf /etc/nginx/sites-available/my-gatsby /etc/nginx/sites-enabled/my-gatsbysudo nginx -t && sudo systemctl reload nginxAfter content changes, rebuild and sync:
cd ~/my-gatsby && npm run buildsudo rsync -a ~/my-gatsby/public/ /var/www/my-gatsby/
Tips
- Gatsby builds want RAM: ≥2 GB VPS helps.
- Do not expose
gatsby developto the internet — only the static build.
ext step
More RAM for static builds: Deploy your Cloud VPS.