Skip to content

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.


On your machine:

Terminal window
npm run build

This 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:

Terminal window
rsync -avz dist/ ubuntu@your-ec2-ip:/var/www/mysite

Or via SCP:

Terminal window
scp -r dist ubuntu@your-ec2-ip:/var/www/mysite

This 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:

Terminal window
sudo apt update
sudo apt install nginx -y

Enable and start:

Terminal window
sudo systemctl enable nginx
sudo systemctl start nginx

4. Create an Nginx config for your site

Section titled “✅ 4. Create an Nginx config for your site”

Create:

Terminal window
sudo nano /etc/nginx/sites-available/mysite

Paste 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.


Terminal window
sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/mysite

Remove the default site (optional):

Terminal window
sudo rm /etc/nginx/sites-enabled/default

Test syntax:

Terminal window
sudo nginx -t

Reload:

Terminal window
sudo systemctl reload nginx

Test:

Terminal window
curl http://your-ec2-ip

Install Certbot:

Terminal window
sudo apt install certbot python3-certbot-nginx -y

Run:

Terminal window
sudo certbot --nginx -d your-domain.com

Done — your Astro static site now has HTTPS.


StepPurpose
Build Astronpm run build → generates dist/
Upload to EC2Copy files to /var/www/mysite
Install NginxServe static files
Configure NginxPoint root to your dist folder
Enable HTTPSUse 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 nginx
sudo systemctl enable nginx
sudo systemctl start nginx
# ---------------------------------------------------
# CREATE SITE FOLDER
# ---------------------------------------------------
sudo mkdir -p $SITE_DIR
sudo 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 <<EOF
server {
listen 80;
server_name $DOMAIN;
root $SITE_DIR;
index index.html;
location / {
try_files \$uri \$uri/ =404;
}
}
EOF"
# ENABLE SITE
sudo ln -sf /etc/nginx/sites-available/wik1 /etc/nginx/sites-enabled/wik1
# REMOVE DEFAULT SITE
sudo rm -f /etc/nginx/sites-enabled/default
# TEST AND RELOAD NGINX
sudo 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"

1️⃣ Upload your Astro dist/ folder to the server:

Section titled “1️⃣ Upload your Astro dist/ folder to the server:”

On your computer:

Terminal window
rsync -avz dist/ ubuntu@YOUR_EC2_IP:/var/www/wik1

Or:

Terminal window
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”
Terminal window
curl http://wik1.evolo.fr

You should see your Astro site.


On the EC2 instance:

Terminal window
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d wik1.evolo.fr

Your site will now be available on https://wik1.evolo.fr.


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:

Terminal window
ssh ubuntu@YOUR_EC2_IP

Create a file, for example:

Terminal window
nano deploy-wik1.sh

Paste the whole script inside.

Save CTRL+O, then exit CTRL+X.


Run:

Terminal window
chmod +x deploy-wik1.sh

This allows Linux to run it as a program.


Simply run:

Terminal window
./deploy-wik1.sh

or:

Terminal window
bash deploy-wik1.sh

Both work.


After the script finishes, upload your local dist/:

Terminal window
rsync -avz dist/ ubuntu@YOUR_EC2_IP:/var/www/wik1

Your site becomes available at:

👉 http://wik1.evolo.fr

Then run Certbot if you want HTTPS:

Terminal window
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.