How to Deploy Your Hexo Site

Hexo is a fast, simple, and powerful static site generator powered by Node.js. Many developers use Hexo to run personal blogs or documentation sites. In this guide, you’ll learn how to deploy your Hexo project to an Ubuntu server using CloudRay, a centralised platform that helps you automate server tasks through Bash scripting, manage infrastructure, and execute repeatable deployments.

This guide assumes you have a basic Hexo project already created. However, If you’re new to Hexo, you can follow the Hexo Getting Started Guide to scaffold your first site.

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 Hexo site
  1. Go to Scripts in your CloudRay project
  2. Click New Script
  3. Name: Deploy Hexo Site. You can give it any name of your choice
  4. Copy this code:
#!/bin/bash

# =============================
# Hexo Deployment Script
# =============================

# =============================
# 1. Install Dependencies
# =============================
sudo apt update && sudo apt install -y curl git nginx
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm install -g pm2 serve
sudo npm install -g hexo-cli

# =============================
# 2. Clone Repo
# =============================
cd /var/www/
git clone "{{repo_url}}" "{{app_name}}"
cd "/var/www/{{app_name}}"

# =============================
# 3. Install & Build Hexo
# =============================
npm install
npx hexo generate

# =============================
# 4. Serve with PM2
# =============================
pm2 start "serve -s public -l 3000" --name hexo-site
pm2 save
pm2 startup

# =============================
# 5. Configure Nginx
# =============================
sudo bash -c "cat > /etc/nginx/sites-available/hexo-site" <<EOL
server {
    listen 80;
    server_name {{domain}};

    location / {
        proxy_pass http://localhost:3000;
        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;
    }
}
EOL

sudo ln -s /etc/nginx/sites-available/hexo-site /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

# =============================
# Done!
# =============================
echo "✅ Hexo site deployed at: http://{{domain}}"

This script handles the entire process of installing dependencies, building your Hexo project, and running it behind Nginx using PM2.

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}}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: The name of the app folder
  • domain: The domain pointing to the server

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 Hexo 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 Hexo 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 Deploy Hexo script

CloudRay will automatically connect to your server, run the Deploy Hexo 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 Hexo site up and running

Screenshot showing Hexo 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 Hexo 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.