</> HTML5Advent
ENFRESDEITPT

// hosting

How to host an Astro site: static and SSR options

A practical guide to deploying an Astro site - the difference between static output and server (SSR) output, how adapters work, the build commands, and how to choose a host for each mode.

HTML source code with anchor and list-item tags shown in colour on a dark screen

Astro can ship your site two very different ways, and which one you pick decides where and how you host it. By default Astro builds a folder of plain HTML, CSS and JS - files any static host can serve. But Astro can also run on a server, rendering pages on demand (SSR) for things like authentication, forms or per-request data. This guide explains both output modes, the build commands behind them, how adapters fit in, and how to choose a host for each.

Static vs server: the core decision

Every hosting choice for Astro flows from one question: does your site need a running server at request time?

  • Static (the default). Pages are rendered once, at build time, into HTML files. There's no server process - you upload the built folder to a CDN or static host and it serves files. Fastest, cheapest, simplest. Ideal for blogs, docs, marketing sites and most content sites.
  • Server / SSR. Pages are rendered per request by a Node (or edge) process. Needed when content depends on the request: logged-in users, form handling, on-the-fly personalisation, or data that must be fresh on every load.

You can also mix the two: keep the site mostly static and opt specific routes into on-demand rendering. The point is to render statically wherever you can, and only pay for a server where you actually need one.

The build commands

Whatever the mode, the workflow is the same two commands - install, then build:

# install dependencies
npm install

# produce the production build
npm run build

# preview the production build locally before deploying
npm run preview

By default npm run build writes a static site to the dist/ folder. That folder is your entire deployable site in static mode - there is nothing else to run.

Configuring the output mode

You control the mode in astro.config.mjs. Static is the default, so a minimal config needs nothing special. To render on the server, you add an adapter - a small package that teaches Astro how to run on a specific platform (Node, or an edge/serverless runtime):

// astro.config.mjs - server (SSR) output with the Node adapter
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';

export default defineConfig({
  output: 'server',
  adapter: node({ mode: 'standalone' }),
});

With the standalone Node adapter, npm run build produces a server entry point you start like any Node app:

# after building with the Node adapter
node ./dist/server/entry.mjs

If you only need a handful of dynamic routes, keep the default static output and opt individual pages out of prerendering instead of switching the whole site to server mode:

---
// src/pages/dashboard.astro - render this page per request
export const prerender = false;
---
JavaScript source code with syntax highlighting shown on a dark editor screen
JavaScript in a code editor - the build step turns your Astro components into the HTML and JS that gets deployed.

Choosing a host by mode

Static hosting

For static output you just need somewhere to serve the contents of dist/ over HTTPS, ideally from a CDN. The build/publish settings are simple:

Build command:    npm run build
Publish/output:   dist

Plenty of platforms do this - managed static hosts, object storage behind a CDN, or a general-purpose host that can serve a folder. Because there's no server to keep alive, static hosting is cheap and effortless to scale. Hosting on European infrastructure is a fine choice here when your audience or data-residency needs point that way.

Server (SSR) hosting

SSR needs a runtime that keeps a process alive. Two broad routes:

  • A Node host / VPS. With the Node adapter you build a standalone server and run it like any Node service. A VPS gives you full control over the process, environment and scaling - handy if you already run other services there.
  • Serverless / edge. Platform-specific adapters package your app to run as functions. Less to manage, but you're tied to that platform's model.

A simple way to run the Node build on your own server is a process manager so it restarts on crash or reboot:

# example: keep the Astro Node server running with PM2
npm install -g pm2
pm2 start ./dist/server/entry.mjs --name astro-site
pm2 save

What a Node server for Astro SSR costs

A PaaS bills the RAM and CPU the process keeps reserved, a VPS bills a flat month. Railway's published rates (read on 20 November 2026: Hobby $5/month including $5 of usage, then $10 per GB of RAM and $20 per vCPU per month) put a small always-on Node process at 512 MB and 0.25 vCPU around $10/month. Contabo's smallest Cloud VPS is 4.40 EUR/month ex. VAT on a 24-month term (list price read on 17 November 2026), and one VPS can run several Astro servers side by side: give each its own PORT, start each under PM2, and let Caddy or Nginx route each domain to its port. Check the memory each one actually holds with pm2 monit before sizing up. Detailed figures are in the Node.js hosting guide.

See Contabo Cloud VPS plans.

What goes in dist/client and dist/server

As soon as an adapter is configured, npm run build splits the output in two: dist/client/ holds everything the browser downloads (prerendered HTML, CSS, JS and the files from public/), and dist/server/ holds the code that renders on-demand pages, with entry.mjs as its entry point. Deploy both folders together, on the same machine, keeping the same relative layout.

  • Standalone mode (mode: 'standalone'): node ./dist/server/entry.mjs serves the rendered pages and the files of dist/client/ by itself. Copy the whole dist/ folder with package.json, run npm install --omit=dev, start it, and put Nginx or Caddy in front for HTTPS. The PORT and HOST environment variables set where it listens.
  • Middleware mode (mode: 'middleware'): entry.mjs exports a handler that you mount in your own Express or Fastify server, and you serve dist/client/ yourself as static files:
// server.mjs - Astro (mode: 'middleware') behind Express
import express from 'express';
import { handler as ssrHandler } from './dist/server/entry.mjs';

const app = express();
app.use('/', express.static('dist/client/'));
app.use(ssrHandler);
app.listen(8080);

Hosting Astro on shared hosting (Bluehost, cPanel)

Static output works on any shared plan: run npm run build on your computer, then upload the contents of dist/ (not the folder itself) into public_html/ by FTP or the cPanel file manager. Set site in astro.config.mjs to your domain first, and if the site lives in a subfolder, set base to that path so links and assets resolve.

Server output is the hard part on shared hosting: the Node process has to stay running, and classic shared plans are built for PHP, not for long-lived Node servers. Some cPanel hosts add a "Setup Node.js App" panel, so check that your plan includes it before you pick server output. Otherwise keep the site static, or move to a VPS where you run entry.mjs under PM2 as shown above.

Quick reference

NeedModeWhat to host
Blog, docs, marketing, contentStatic (default)The dist/ folder on a CDN/static host
Mostly static, a few dynamic routesStatic + prerender = false per pageA host/adapter that supports on-demand routes
Auth, forms, per-request data everywhereServer (SSR)A Node runtime / VPS or serverless platform

How to decide

Start static - it's the default for a reason: cheaper, faster and simpler to host. Only reach for the server adapter when a real requirement (logged-in state, form processing, always-fresh data) forces per-request rendering, and even then consider opting just those routes out of prerendering rather than running the whole site on a server. Match the host to the mode you end up with: a CDN-backed static host for built files, or a Node-capable VPS / serverless platform when you genuinely need a server.