Goran Stimac
Menu

Astro is a good fit for static publishing because it keeps the runtime simple. Once the site is built, Nginx only needs to do one job: serve the files quickly and consistently.

That is the main reason static sites are easy to scale and inexpensive to host. The tricky part is not the framework itself, but the deployment process around it.

Start With a Complete Build

Always deploy the full output directory from the build step. A partial upload is the most common reason for broken CSS, missing images, or HTML pages that load without their assets.

Before you copy anything to the server, check that the build contains all expected directories:

npm run build
ls -la dist

If the site uses hashed assets or optimized images, make sure those folders are present in the final output too. Do not copy only the HTML files.

Use A Simple Nginx Layout

For a static site, the Nginx config should be straightforward. The goal is to serve assets directly, return proper 404 responses when something is missing, and avoid rewriting requests into HTML by mistake.

server {
    listen 443 ssl http2;
    server_name example.com www.example.com;

    root /var/www/example.com/current;
    index index.html;

    location ^~ /_astro/ {
        try_files $uri =404;
        access_log off;
        expires 1y;
        add_header Cache-Control "public, max-age=31536000, immutable" always;
    }

    location ^~ /__optimized/ {
        try_files $uri =404;
        access_log off;
        expires 1y;
        add_header Cache-Control "public, max-age=31536000, immutable" always;
    }

    location / {
        try_files $uri $uri/ /index.html;
    }
}

That pattern keeps the site predictable. If an asset is missing, Nginx should return a real 404 instead of serving a fallback HTML page.

Fix Permissions Before You Reload

Permissions matter more than many people expect. If the web server cannot traverse a directory, the site can fail even when the files are present.

sudo chown -R ubuntu:ubuntu /var/www/example.com/current
sudo find /var/www/example.com/current -type d -exec chmod 755 {} \;
sudo find /var/www/example.com/current -type f -exec chmod 644 {} \;
sudo nginx -t
sudo systemctl reload nginx

That keeps the deployment safe and easy to debug. If the config tests cleanly but the browser still shows errors, inspect the access and error logs before changing the application.

Keep The Deployment Repeatable

The best deployment is the one you can repeat without guessing. A reliable process usually looks like this:

  1. Build the site locally.
  2. Upload the full dist directory.
  3. Promote it to the live web root.
  4. Fix ownership and permissions.
  5. Test the Nginx config.
  6. Reload the service.

That is simple, but it prevents a lot of downtime. It also makes future troubleshooting much faster because the failure point is easier to identify.

If you run a static Astro site on a small VPS, this is the setup I would recommend first.

Relevant services

These service pages are matched from the subject matter of this article, creating a cleaner path from educational content to implementation work.

Continue reading

Based on shared categories first, then the strongest overlap in tags.