← Todas las notas← All notes
Deploying a static Astro site on Debian + nginx
This site is a static build. npm run build produces a dist/ folder of plain
HTML, CSS and JS — nothing to run, nginx just serves the files. Here’s the full
path from a clean Debian box to a live site.
1. Build locally
npm install
npm run build # outputs to ./dist
2. Copy the build to the server
rsync -avz --delete dist/ deploy@your-server:/var/www/emmanuelmadrid/
--delete keeps the server folder in sync by removing files that no longer
exist in the build.
3. nginx server block
Create /etc/nginx/sites-available/emmanuelmadrid:
server {
listen 80;
listen [::]:80;
server_name emmanuelmadrid.dev www.emmanuelmadrid.dev;
root /var/www/emmanuelmadrid;
index index.html;
# Astro emits /notes/my-note/index.html — serve directory-style URLs.
location / {
try_files $uri $uri/ $uri.html =404;
}
# Cache fingerprinted assets aggressively.
location /_astro/ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
Enable it and reload:
sudo ln -s /etc/nginx/sites-available/emmanuelmadrid /etc/nginx/sites-enabled/
sudo nginx -t # test the config
sudo systemctl reload nginx
4. HTTPS with Let’s Encrypt
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d emmanuelmadrid.dev -d www.emmanuelmadrid.dev
Certbot rewrites the server block to listen on 443 and sets up auto-renewal via a systemd timer.
Checklist
| Step | Command |
|---|---|
| Build | npm run build |
| Upload | rsync -avz --delete dist/ … |
| Test nginx | sudo nginx -t |
| Reload | sudo systemctl reload nginx |
| TLS | sudo certbot --nginx -d … |
Next time I’ll wire this into a one-command deploy script and, eventually, a CI pipeline that builds and ships on every push.