How to Deploy Your Eleventy Site

Eleventy is a fast, flexible static site generator written in JavaScript. It allows you to create modern, highly performant static websites using templates, Markdown, and data files. In this guide, we’ll walk you through deploying an Eleventy project to an Ubuntu server using CloudRay, a platform that helps you manage infrastructure and automate deployments with reusable Bash scripts.

This guide assumes you already have an Eleventy project set up. If not, you can clone the Eleventy Base Blog starter to get started.

Contents

Adding Servers to CloudRay

Before getting started, make sure your machine is added to a CloudRay project and connected using the CloudRay Agent.

Create a Deployment Script

Now that your machine is connected to CloudRay, let’s create a reusable Bash script to automate the deployment process. You need to follow these steps to create the script in CloudRay.

Screenshot for deployment script of Eleventy site
  1. Go to Scripts in your CloudRay project
  2. Click New Script
  3. Name: Deploy Eleventy Site. You can give it any name of your choice
  4. Copy this code:
#!/bin/bash

# Exit on error
set -e

echo "📦 Updating system and installing dependencies..."
sudo apt update && sudo apt install -y \
    curl git nginx

echo "🧰 Installing Node.js LTS..."
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

echo "🚀 Installing global packages..."
sudo npm install -g pm2 serve


echo "📁 Cloning or updating Eleventy repo..."
sudo mkdir -p /var/www
sudo chown -R "$USER":"$USER" /var/www
cd /var/www
if [ -d "{{app_name}}/.git" ]; then
  echo "🔁 Existing repo detected — fetching latest changes..."
  cd "{{app_name}}"
  git fetch --all --prune
  # Adjust branch if your default branch is not 'main'
  git reset --hard origin/main
else
  git clone "{{repo_url}}" "{{app_name}}"
  cd "{{app_name}}"
fi

echo "📦 Installing project dependencies..."
npm install

echo "🏗️ Building the Eleventy site..."
npx @11ty/eleventy

echo "📡 Serving with PM2 on port {{port}}..."
pm2 start "serve _site -l {{port}}" --name "{{app_name}}"

# Configure PM2 to start on boot for the current user and persist the process list
sudo env PATH=$PATH pm2 startup systemd -u "$USER" --hp "$HOME" >/dev/null
pm2 save

echo "🌐 Configuring Nginx reverse proxy..."
NGINX_CONF="/etc/nginx/sites-available/{{app_name}}"
sudo tee "$NGINX_CONF" > /dev/null <<EOF
server {
    listen 80;
    server_name {{domain}};

    location / {
        proxy_pass http://localhost:{{port}};
        proxy_http_version 1.1;
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host \$host;
        proxy_cache_bypass \$http_upgrade;
    }
}
EOF

echo "🔗 Enabling Nginx config and restarting..."
sudo ln -sf "$NGINX_CONF" /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t && sudo systemctl reload nginx

echo "✅ Deployment complete! Access your site at http://{{domain}}"

Here is what the Deploy Eleventy Site does:

  • Installs system dependencies and Node.js
  • Clone your Eleventy project from a Git repository
  • Build the project
  • Serves the site with PM2
  • Sets up Nginx as a reverse proxy

Define the Variable Group

To make this script reusable across multiple projects or servers, you’ll define a variable group inside CloudRay. These variables dynamically fill in the placeholders like {{repo_url}}, {{app_name}}, {{port}} and {{domain}}. CloudRay processes all scripts as Liquid templates.

Screenshot of adding a new variable group

To ensure that these values are automatically substituted when the script runs, follow these steps to create a variable group:

  1. Navigate to Variable Groups: In your CloudRay project, go to “Scripts” in the top menu and click on “Variable Groups”.
  2. Create a new Variable Group: Click on “Variable Group”.
  3. Add the following variables:
  • repo_url: The URL of your GitHub repository
  • app_name: Your Eleventy deployment directory
  • domain: This is the name of your domain, e.g., myapp.example.com
  • port: The port your Eleventy application listens on (e.g., 3000)

Since the variables is setup, proceed with running the scripts with CloudRay

Run the Deployment Script

CloudRay uses Runlogs to execute scripts on your servers while providing real-time logs of the execution process.

Once the script is saved, you can deploy your Eleventy site by creating a Runlog:

  1. Navigate to Runlogs: In your CloudRay project, go to the Runlogs section in the top menu.
  2. Create a New Runlog: Click on New Runlog.
  3. Configure the Runlog: Fill in the required details:
  • Server: Select the server you added earlier.
  • Script: Choose the “Deploy Eleventy Site”
  • Variable Group (optional): Select the variable group you created earlier.
Screenshot of creating a new runlog
  1. Execute the Script: Click on Run Now to start the execution.
Screenshot of the output of the Eleventy deployment script

CloudRay will automatically connect to your server, run the Deploy Eleventy Site, and provide live logs to track the process. If any errors occur, you can review the logs to troubleshoot the issue.

Once the deployment is complete, you can visit http://<your_domain>. You should see your Eleventy site up and running

Screenshot showing Eleventy Site running

Next Step

To improve your deployment and security:

  • You can use Let’s Encrypt to add HTTPS support
  • Set up automatic redeployment with webhooks or CI/CD

Summary

With CloudRay, deploying your Eleventy site to Ubuntu becomes a structured and repeatable process. Scripts remain organised, server access is centralised, and you can easily tweak configurations with variable groups.

For more deployment guides and use cases, check out our CloudRay Guides or explore the CloudRay Docs.

Avatar for Olusegun Durojaye

Written by Olusegun Durojaye
CloudRay Team