How to Deploy Your Hugo Site
Hugo is a fast and flexible static site generator that enables developers to build modern websites quickly. In this guide, we’ll walk through how to deploy a Hugo site to an Ubuntu server using CloudRay, a centralised platform for managing infrastructure and automating deployment using Bash scripts.
This guide assumes you already have a Hugo project stored in a Git repository. If not, you can start by following Hugo’s Quick Start guide to create one.
Contents
- Adding Servers to CloudRay
- Create a Deployment Script
- Define the Variable Group
- Run the Deployment Script
- Next Step
- Summary
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.

- Go to Scripts in your CloudRay project
- Click New Script
- Name:
Deploy Hugo Site
. You can give it any name of your choice - Copy this code:
#!/bin/bash
# Exit on error
set -e
# === Commands ===
sudo apt update
sudo apt install hugo nginx git -y
sudo mkdir {{project_dir}}
cd {{project_dir}}
sudo git clone --recurse-submodules "{{repo}}" .
sudo hugo -D
sudo chown -R www-data:www-data {{project_dir}}/public
sudo tee /etc/nginx/sites-available/{{domain}} > /dev/null <<EOF
server {
listen 80;
server_name {{domain}} www.{{domain}};
root {{project_dir}}/public;
index index.html;
access_log /var/log/nginx/{{domain}}_access.log;
error_log /var/log/nginx/{{domain}}_error.log;
location / {
try_files \$uri \$uri/ =404;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/{{domain}} /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
echo "✅ Hugo site deployed and available at http://${{domain}}"
Here is what the Deploy Hugo Site
does:
- Install Hugo, Git, and Nginx
- Clone your Hugo project from a Git repository
- Build the project
- Configure Nginx to serve the generated site
Define the Variable Group
Now, before running the deployment script, you need to define values for the placeholders {{domain}}
, {{repo}}
, and {{project_dir}}
used in the scrips. CloudRay processes all scripts as Liquid templates. This allows you to use variables dynamically across different servers.

To ensure that these values are automatically substituted when the script runs, follow these steps to create a variable Group:
- Navigate to Variable Groups: In your CloudRay project, go to “Scripts” in the top menu and click on “Variable Groups”.
- Create a new Variable Group: Click on “Variable Group”.
- Add the following variables:
domain
: Your Hugo site domain namerepo
: The URL of your GitHub repositoryproject_dir
: Your Hugo deployment directory
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 Hugo site by creating a Runlog:
- Navigate to Runlogs: In your CloudRay project, go to the Runlogs section in the top menu.
- Create a New Runlog: Click on New Runlog.
- Configure the Runlog: Fill in the required details:
- Server: Select the server you added earlier.
- Script: Choose the “Deploy Hugo Site”
- Variable Group (optional): Select the variable group you created earlier.

- Execute the Script: Click on Run Now to start the execution.

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