Plaintext Engineering
0%

📦 Deploy an Astro.js Site on a Droplet with Nginx + SSL

Jun 13, 2025 • 3 min read

This tutorial walks step‑by‑step through deploying an Astro.js site to a fresh DigitalOcean Droplet using a static build. You’ll copy the generated files to the server and configure Nginx to serve them efficiently. Optionally, you’ll add HTTPS via Let’s Encrypt (Certbot).

What You Will Build

Prerequisites

Step 1: Build your Astro site

npm run build
# or
yarn build

By default, Astro outputs static files into the dist/ directory:

ls dist

Step 2: Prepare the server

SSH into the Droplet and install Nginx:

ssh root@your_droplet_ip
apt update && apt upgrade -y
apt install -y nginx
systemctl status nginx

Step 3: Transfer static files with SCP (or rsync)

From your local machine (not over SSH), copy your dist contents to the server:

scp -r dist/* root@your_droplet_ip:/var/www/astro-site/

If the directory doesn’t exist yet:

ssh root@your_droplet_ip "mkdir -p /var/www/astro-site"

Alternatively, use rsync (faster incremental sync):

rsync -avz --delete dist/ root@your_droplet_ip:/var/www/astro-site/

Step 4: Configure Nginx to serve the site

Create a new site configuration:

nano /etc/nginx/sites-available/astro-site

Add this (replace yourdomain.com with your domain or use the server IP for testing):

server {
    listen 80;
    server_name yourdomain.com;  # or your server IP

    root /var/www/astro-site;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    access_log /var/log/nginx/astro-site.access.log;
    error_log  /var/log/nginx/astro-site.error.log;
}

Enable and test the config:

ln -s /etc/nginx/sites-available/astro-site /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default  # optional
nginx -t
systemctl reload nginx

Step 5: Access your site

You should now see your Astro.js site served by Nginx.

Step 6: Updating your site

Rebuild locally and sync again:

npm run build
scp -r dist/* root@your_droplet_ip:/var/www/astro-site/
# or
rsync -avz --delete dist/ root@your_droplet_ip:/var/www/astro-site/

No Nginx restart is needed for static files.

Optional: Add HTTPS with Certbot (Let’s Encrypt)

apt install -y certbot python3-certbot-nginx
certbot --nginx -d yourdomain.com

Follow the prompts; Certbot will configure Nginx for TLS automatically.

Summary Table

StepCommand or Action
Build Astro staticnpm run build
Copy files (SCP)scp -r dist/* root@your_droplet_ip:/var/www/astro-site/
Copy files (rsync)rsync -avz --delete dist/ root@your_droplet_ip:/var/www/astro-site/
Edit Nginx confignano /etc/nginx/sites-available/astro-site
Enable siteln -s /etc/nginx/sites-available/astro-site /etc/nginx/sites-enabled/
Test Nginx confignginx -t
Reload Nginxsystemctl reload nginx
Install Certbotapt install -y certbot python3-certbot-nginx
Obtain SSL certcertbot --nginx -d yourdomain.com

This straightforward static deployment leverages Nginx’s performance and simplicity. Use rsync for fast updates, and enable HTTPS to protect users and improve SEO.

Sources

Related articles