Gatsby genera sitios React estáticos. En un VPS compilas una vez y sirves solo HTML/JS/CSS con Nginx.
Pasos
Asegura Node.js LTS y el CLI de Gatsby:
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 --versionCrea el proyecto y genera el build de producción:
cd ~ && npx gatsby new mi-gatsbycd ~/mi-gatsbynpm run buildCopia public/ a Nginx:
sudo mkdir -p /var/www/mi-gatsbysudo rsync -a ~/mi-gatsby/public/ /var/www/mi-gatsby/sudo tee /etc/nginx/sites-available/mi-gatsby >/dev/null <<'EOF'server { listen 80; server_name ejemplo.com; root /var/www/mi-gatsby; index index.html; try_files $uri $uri/ /index.html;}EOFsudo ln -sf /etc/nginx/sites-available/mi-gatsby /etc/nginx/sites-enabled/mi-gatsbysudo nginx -t && sudo systemctl reload nginxTras cambios de contenido, rebuild y sync:
cd ~/mi-gatsby && npm run buildsudo rsync -a ~/mi-gatsby/public/ /var/www/mi-gatsby/
Consejos
- Gatsby consume más RAM en build: un VPS con ≥2 GB ayuda.
- o ejecutes
gatsby developexpuesto a Internet; solo el build estático.
Siguiente paso
Más RAM para builds estáticos: Despliega tu VPS Cloud.