astro static deployemnt
Deploying a static Astro site on an EC2 instance with Nginx is simple — no Node server, no PM2, no SSR. Nginx directly serves the files inside the dist/ folder.
Here is the cleanest and correct deployment guide.
✅ 1. Build your Astro site locally
Section titled “✅ 1. Build your Astro site locally”On your machine:
npm run buildThis creates:
dist/ index.html assets/ images/ ...✅ 2. Upload the dist folder to your EC2 instance
Section titled “✅ 2. Upload the dist folder to your EC2 instance”From your computer:
rsync -avz dist/ ubuntu@your-ec2-ip:/var/www/mysiteOr via SCP:
scp -r dist ubuntu@your-ec2-ip:/var/www/mysiteThis produces:
/var/www/mysite/ index.html assets/✅ 3. Install Nginx (if not already installed)
Section titled “✅ 3. Install Nginx (if not already installed)”SSH into EC2:
sudo apt updatesudo apt install nginx -yEnable and start:
sudo systemctl enable nginxsudo systemctl start nginx✅ 4. Create an Nginx config for your site
Section titled “✅ 4. Create an Nginx config for your site”Create:
sudo nano /etc/nginx/sites-available/mysitePaste the following:
server { listen 80; server_name your-domain.com;
root /var/www/mysite; index index.html;
location / { try_files $uri $uri/ =404; }}Save and exit.
✅ 5. Enable the site
Section titled “✅ 5. Enable the site”sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/mysiteRemove the default site (optional):
sudo rm /etc/nginx/sites-enabled/defaultTest syntax:
sudo nginx -tReload:
sudo systemctl reload nginx🌍 Your static Astro site is now live!
Section titled “🌍 Your static Astro site is now live!”Test:
curl http://your-ec2-ip🔐 6. Add HTTPS (recommended)
Section titled “🔐 6. Add HTTPS (recommended)”Install Certbot:
sudo apt install certbot python3-certbot-nginx -yRun:
sudo certbot --nginx -d your-domain.comDone — your Astro static site now has HTTPS.
📌 Summary
Section titled “📌 Summary”| Step | Purpose |
|---|---|
| Build Astro | npm run build → generates dist/ |
| Upload to EC2 | Copy files to /var/www/mysite |
| Install Nginx | Serve static files |
| Configure Nginx | Point root to your dist folder |
| Enable HTTPS | Use Certbot |
🎁 Optional: want a full deployment script like we did for SSR?
Section titled “🎁 Optional: want a full deployment script like we did for SSR?”I can generate a complete static deployment script (copy + Nginx + Certbot). Just tell me:
- your domain
- your site folder name (
mysite?) - Ubuntu version (probably 22.04)
I’ll generate it.
Perfect — here is your fully customized static Astro deployment script for:
- Domain:
wik1.evolo.fr - Site folder:
/var/www/wik1 - Stack: Ubuntu + Nginx + Certbot
- Deployment type: static Astro (
dist/folder)
Just copy/paste the script into your EC2 instance.
🚀 STATIC ASTRO DEPLOYMENT SCRIPT (wik1.evolo.fr)
Section titled “🚀 STATIC ASTRO DEPLOYMENT SCRIPT (wik1.evolo.fr)”#!/bin/bash
# ---------------------------------------------------# CONFIGURATION# ---------------------------------------------------DOMAIN="wik1.evolo.fr"SITE_DIR="/var/www/wik1"
# ---------------------------------------------------# UPDATE SYSTEM# ---------------------------------------------------sudo apt update && sudo apt upgrade -y
# ---------------------------------------------------# INSTALL NGINX# ---------------------------------------------------sudo apt install -y nginxsudo systemctl enable nginxsudo systemctl start nginx
# ---------------------------------------------------# CREATE SITE FOLDER# ---------------------------------------------------sudo mkdir -p $SITE_DIRsudo chown -R $USER:$USER $SITE_DIR
echo "⚠️ Now upload your Astro dist/ folder to: $SITE_DIR"echo "Example:"echo "rsync -avz dist/ ubuntu@your-ec2-ip:$SITE_DIR"echo ""
# ---------------------------------------------------# CREATE NGINX CONFIG# ---------------------------------------------------sudo bash -c "cat >/etc/nginx/sites-available/wik1 <<EOFserver { listen 80; server_name $DOMAIN;
root $SITE_DIR; index index.html;
location / { try_files \$uri \$uri/ =404; }}EOF"
# ENABLE SITEsudo ln -sf /etc/nginx/sites-available/wik1 /etc/nginx/sites-enabled/wik1
# REMOVE DEFAULT SITEsudo rm -f /etc/nginx/sites-enabled/default
# TEST AND RELOAD NGINXsudo nginx -t && sudo systemctl reload nginx
echo "---------------------------------------------------"echo "🚀 Static site configured for http://$DOMAIN"echo "---------------------------------------------------"echo ""echo "To enable HTTPS, run the following:"echo "sudo apt install certbot python3-certbot-nginx -y"echo "sudo certbot --nginx -d $DOMAIN"📤 After running the script
Section titled “📤 After running the script”1️⃣ Upload your Astro dist/ folder to the server:
Section titled “1️⃣ Upload your Astro dist/ folder to the server:”On your computer:
rsync -avz dist/ ubuntu@YOUR_EC2_IP:/var/www/wik1Or:
scp -r dist/* ubuntu@YOUR_EC2_IP:/var/www/wik1🔎 2️⃣ Check Nginx is serving the site
Section titled “🔎 2️⃣ Check Nginx is serving the site”curl http://wik1.evolo.frYou should see your Astro site.
🔐 3️⃣ Enable HTTPS (recommended)
Section titled “🔐 3️⃣ Enable HTTPS (recommended)”On the EC2 instance:
sudo apt install certbot python3-certbot-nginx -ysudo certbot --nginx -d wik1.evolo.frYour site will now be available on https://wik1.evolo.fr.
🎉 Done!
Section titled “🎉 Done!”If you want, I can also generate:
- A multi-site Nginx config (wik1, test1, api, etc.)
- A zero-downtime deploy script
- A script to auto-sync dist via GitHub Actions
Just tell me!
Here’s exactly where to put the deployment script on your EC2 instance and how to run it.
✅ 1. Create the script on your EC2 instance
Section titled “✅ 1. Create the script on your EC2 instance”SSH into your EC2 server:
ssh ubuntu@YOUR_EC2_IPCreate a file, for example:
nano deploy-wik1.shPaste the whole script inside.
Save CTRL+O, then exit CTRL+X.
✅ 2. Make the script executable
Section titled “✅ 2. Make the script executable”Run:
chmod +x deploy-wik1.shThis allows Linux to run it as a program.
✅ 3. Run the script
Section titled “✅ 3. Run the script”Simply run:
./deploy-wik1.shor:
bash deploy-wik1.shBoth work.
✅ 4. Upload your Astro dist folder
Section titled “✅ 4. Upload your Astro dist folder”After the script finishes, upload your local dist/:
rsync -avz dist/ ubuntu@YOUR_EC2_IP:/var/www/wik1📌 You’re done!
Section titled “📌 You’re done!”Your site becomes available at:
Then run Certbot if you want HTTPS:
sudo certbot --nginx -d wik1.evolo.fr⚠️ Need me to generate a safer version of the script (with checks, logging, backups)?
Section titled “⚠️ Need me to generate a safer version of the script (with checks, logging, backups)?”Just tell me.