Skip to content

Deploy Astro to Any Cloud Provider

Astro projects can be deployed in two ways:

  • As a web server or middleware (SSR)
  • As a static website

In this guide, I’ll show you how to deploy both types of Astro projects. If you’re not sure which one fits your use case, try the SSR option first, as it works for most static websites as well.

What You’ll Need

  • A server with a public IP address, SSH access and running a fresh installation of Ubuntu 22.04. Don’t know which cloud provider to use? Try DigitalOcean, Vultr, or Hetzner.
  • An Astro project (if you don’t have one, clone this starter: astroship)
  • (Optional) A custom domain

Deployment Steps

  • Create a server on your cloud provider
  • (Optional, required for Astro SSR) Add the Node adapter to your Astro project
  • Create a Dockerfile
  • Deploy the project from a local folder or GitHub/Bitbucket

What You’ll Get

  • A deployed Astro project without vendor lock-in
  • HTTPS with an auto-generated or custom domain
  • WAF with the default ruleset recommended by OWASP
  • Rate limiter
  • CI/CD if you deploy from GitHub or Bitbucket

Deploying Astro with SSR

If your project uses server-side rendering (SSR), you’ll need to use the Astro Node adapter. This option works for most Astro static websites as well.

  1. Add the Node adapter to your Astro project (run the command below in the project root):

    Terminal window
    npx astro add node
  2. Create a Dockerfile in the project root with the following content:

    FROM node:lts AS runtime
    WORKDIR /app
    COPY . .
    RUN npm install
    RUN npm run build
    ENV HOST=0.0.0.0
    ENV PORT=4321
    EXPOSE 4321
    CMD ["node", "./dist/server/entry.mjs"]

Deploy Astro SSR from a Local Folder

You can deploy Astro projects directly from the local folders on your development machine with TurboCloud:

  • If the project is a Git repository, TurboCloud uploads files added to Git (you can check what will be uploaded with the command git ls-files --recurse-submodules). Don’t forget to add the Dockerfile created before to Git with git add Dockerfile.

  • If you don’t use Git, all files inside the project’s folder will be uploaded.

Now everything is ready, let’s deploy:

  1. Run the command below in the root of your Astro project (replace server_ip with your server’s actual IP):

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip -p 4321

    If you want to use a custom domain, add the -d parameter (the DNS A record of your domain should point to the IP address of the server you’re deploying to):

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip -p 4321 -d some_domain.com
  2. After deployment, you’ll receive an auto-generated URL to access your site. If you specified your own domain in step 1, you can use that domain as well.

  3. (Optional) Visit console.turbocloud.dev to manage and monitor deployments. You can add custom domains, set up load balancing across servers, and more.

  4. To deploy again, run the same command as you did for the first deployment:

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip

Deploy Astro SSR from GitHub / Bitbucket

  1. Push the Dockerfile with all changes to a remote Git repository (GitHub and Bitbucket are supported).

  2. SSH into a server with fresh Ubuntu 22.04 and a public IP address, and install TurboCloud (replace server_ip with your server’s actual IP; installation takes around a minute):

    Terminal window
    ssh root@server_ip
    curl https://turbocloud.dev/setup | bash -s
  3. Visit console.turbocloud.dev to add and deploy your Astro project. In the port field, type in 4321 as we use this port in the Dockerfile. You can deploy projects, add custom domains, set up load balancing across servers, and more.


Deploying Static Astro Sites/Apps

If you’re using Astro as a static site generator (e.g., using a theme from astro.build/themes and customizing it), all you need is a simple Dockerfile:

  • Create a Dockerfile in the root of your Astro project with the following content:

    FROM node:lts AS build
    WORKDIR /app
    COPY . .
    RUN npm install
    RUN npm run build
    FROM httpd:2.4 AS runtime
    COPY --from=build /app/dist /usr/local/apache2/htdocs/
    EXPOSE 80

Deploy Astro Static Website/App from a Local Folder

You can deploy Astro projects directly from the local folders on your development machine with TurboCloud:

  • If the project is a Git repository, TurboCloud uploads files added to Git (you can check what will be uploaded with the command git ls-files --recurse-submodules). Don’t forget to add the Dockerfile created before to Git with git add Dockerfile.

  • If you don’t use Git, all files inside the project’s folder will be uploaded.

Now everything is ready, let’s deploy:

  1. Run the command below in the root of your Astro project (replace server_ip with your server’s actual IP):

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip -p 80

    If you want to use a custom domain, add the -d parameter (the DNS A record of your domain should point to the IP address of the server you’re deploying to):

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip -p 80 -d some_domain.com
  2. After deployment, you’ll receive an auto-generated URL to access your site. If you specified your own domain in step 1, you can use that domain as well.

  3. (Optional) Visit console.turbocloud.dev to manage and monitor deployments. You can add custom domains, set up load balancing across servers, and more.

  4. To deploy again, run the same command as you did for the first deployment:

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip

Deploy Astro Static Website/App from GitHub / Bitbucket

  1. Push the Dockerfile with all changes to a remote Git repository (GitHub and Bitbucket are supported).

  2. SSH into a server with fresh Ubuntu 22.04 and a public IP address, and install TurboCloud (replace server_ip with your server’s actual IP; installation takes around a minute):

    Terminal window
    ssh root@server_ip
    curl https://turbocloud.dev/setup | bash -s
  3. Visit console.turbocloud.dev to add and deploy your Astro project. In the port field, type in 80 as we use this port in the Dockerfile. You can deploy projects, add custom domains, set up load balancing across servers, and more.