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.
-
Add the Node adapter to your Astro project (run the command below in the project root):
Terminal window npx astro add node -
Create a Dockerfile in the project root with the following content:
FROM node:lts AS runtimeWORKDIR /appCOPY . .RUN npm installRUN npm run buildENV HOST=0.0.0.0ENV PORT=4321EXPOSE 4321CMD ["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 withgit 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:
-
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 4321If 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 -
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.
-
(Optional) Visit console.turbocloud.dev to manage and monitor deployments. You can add custom domains, set up load balancing across servers, and more.
-
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
-
Push the Dockerfile with all changes to a remote Git repository (GitHub and Bitbucket are supported).
-
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_ipcurl https://turbocloud.dev/setup | bash -s -
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 buildWORKDIR /appCOPY . .RUN npm installRUN npm run buildFROM httpd:2.4 AS runtimeCOPY --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 withgit 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:
-
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 80If 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 -
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.
-
(Optional) Visit console.turbocloud.dev to manage and monitor deployments. You can add custom domains, set up load balancing across servers, and more.
-
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
-
Push the Dockerfile with all changes to a remote Git repository (GitHub and Bitbucket are supported).
-
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_ipcurl https://turbocloud.dev/setup | bash -s -
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.