Skip to content

Deploy your Astro Site to is*hosting

is*hosting is a hosting provider offering VPS and dedicated servers in 40+ locations that you can use to self-host a static or server-rendered (SSR) Astro site. A VPS is suitable when your Astro site uses SSR and requires a persistent server, database connections, background jobs, cron jobs, or API routes.

To deploy your Astro site to an is*hosting VPS, you will need:

  • An Astro project
  • An is*hosting VPS running Ubuntu with SSH access and root or sudo privileges
  • A domain name pointing to your VPS
  • A Node.js version that meets Astro’s minimum requirements installed on your VPS

Your Astro project can be deployed to an is*hosting VPS as a static site or as an on-demand rendered site.

Your Astro project is a static site by default. You don’t need any extra Astro configuration to deploy a static site to an is*hosting VPS.

To enable on-demand rendering in your Astro project, add the Node.js adapter with the following astro add command. This will install the adapter and configure it in standalone mode in your astro.config.mjs file in one step.

Terminal window
npx astro add node

You can deploy to an is*hosting VPS by building your site on the server and serving it with a web server.

The following instructions use Nginx as the web server, and PM2 to keep the Node.js server of an on-demand rendered site running.

  1. Connect to your VPS using SSH and install both the web server and Git:

    Terminal window
    apt update
    apt install nginx git

    The server commands in this guide assume you are logged in as root. If you use another account, run administrative commands with sudo.

  2. Clone your Astro project to your VPS, install its dependencies, and build your site:

    Terminal window
    cd /var/www
    git clone YOUR_REPOSITORY_URL astro
    cd astro
    npm install
    npm run build
  1. Create an Nginx configuration file at /etc/nginx/sites-available/astro to serve the generated dist/ folder:

    /etc/nginx/sites-available/astro
    server {
    listen 80;
    server_name your.domain.com;
    root /var/www/astro/dist;
    index index.html;
    error_page 404 /404.html;
    location / {
    try_files $uri $uri/ $uri.html =404;
    }
    }
  2. Enable the Nginx configuration and reload Nginx:

    Terminal window
    ln -s /etc/nginx/sites-available/astro /etc/nginx/sites-enabled/
    nginx -t
    systemctl reload nginx
  1. Install PM2 and use it to start the Node.js server:

    Terminal window
    npm install -g pm2
    HOST=127.0.0.1 PORT=4321 pm2 start dist/server/entry.mjs --name astro-app
  2. Configure PM2 to restart the Node.js server after a reboot:

    Terminal window
    pm2 startup && pm2 save
  3. Create an Nginx configuration file at /etc/nginx/sites-available/astro to forward requests to the Node.js server:

    /etc/nginx/sites-available/astro
    server {
    listen 80;
    server_name your.domain.com;
    location / {
    proxy_pass http://127.0.0.1:4321;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    }
  4. Enable the Nginx configuration and reload Nginx:

    Terminal window
    ln -s /etc/nginx/sites-available/astro /etc/nginx/sites-enabled/
    nginx -t
    systemctl reload nginx

After your domain points to the VPS, you can use Certbot to configure HTTPS for either a static or SSR deployment. Make sure ports 80 and 443 are accessible.

  1. Install Certbot and its Nginx plugin:

    Terminal window
    apt install -y certbot python3-certbot-nginx
  2. Request a certificate for your domain:

    Terminal window
    certbot --nginx -d your.domain.com

    Replace your.domain.com with your domain and follow the prompts.

  3. Test automatic certificate renewal:

    Terminal window
    certbot renew --dry-run

To deploy changes to your site, pull the latest changes, install dependencies, and rebuild your site:

Terminal window
cd /var/www/astro
git pull
npm install
npm run build

If your site is on-demand rendered, restart the PM2 process for the changes to take effect:

Terminal window
pm2 restart astro-app

More Deployment Guides

Contribute Community Sponsor