How to Use Hugo for Serving a Website Without a Database
How to Use Hugo for Serving a Website Without a Database
Introduction
Many websites use databases such as MySQL, PostgreSQL, or MongoDB to store and manage their content. However, not every website needs a database.
For blogs, documentation websites, company websites, and portfolios, a static website generator can be a simpler alternative.
Hugo is a fast and flexible static site generator written in Go. It takes content written in Markdown, combines it with templates and themes, and generates a complete website consisting of HTML, CSS, JavaScript, images, and other static files.
Unlike traditional dynamic websites, Hugo does not require a database to store blog posts or retrieve content when visitors open a page.
In this guide, we will install Hugo on Ubuntu, create a website, add blog posts, generate static files, and publish the website using Nginx.
Understanding Hugo
Hugo is an open-source static site generator used to build websites and blogs.
It works by converting content files into ready-to-serve website files.
For example, when an administrator creates a blog post using Markdown, Hugo processes that content and generates an HTML page.
The generated files can then be served by a web server such as Nginx or Apache.
Why Use Hugo?
Some important advantages of Hugo include:
- No database required: Blog posts and pages can be stored as Markdown files.
- Fast performance: Hugo generates static pages that can be served directly to visitors.
- Simple content management: Articles can be created and edited using a text editor.
- Easy deployment: The generated website can be hosted on a normal web server.
- Better security surface: There is no database or dynamic application backend required for a basic static website.
- Version control: Content and configuration can be maintained using Git.
Static Website vs Dynamic Website
Before setting up Hugo, it is important to understand the difference between static and dynamic websites.
Dynamic Website
A traditional dynamic website often uses an application server and database.
For example, when a visitor opens a blog post, the application may retrieve the article from a database and generate the page.
A typical architecture looks like this:
Visitor
|
v
Web Server
|
v
Application
|
v
Database
|
v
Generated Web Page
This architecture is useful for websites that require user accounts, frequent database updates, personalized content, or complex business logic.
Static Website
A static website uses pre-generated HTML, CSS, JavaScript, and other files.
Hugo generates these files before visitors access the website.
A typical architecture looks like this:
Administrator
|
v
Markdown Content
|
v
Hugo
|
v
Generated HTML, CSS and JS
|
v
Nginx
|
v
Visitor
When a visitor requests a page, Nginx serves the already-generated files. Hugo does not need to generate the page for every visitor.
This is why a basic Hugo website does not require a database.
Understanding How Hugo Works
Hugo follows a simple content generation process.
- Content: Articles and pages are written in Markdown files.
- Configuration: Website settings are stored in configuration files.
- Themes and templates: Themes control the website’s appearance and page layout.
- Build process: Hugo combines the content, configuration, and templates.
- Output: Hugo generates static website files in the
publicdirectory. - Web server: Nginx serves those generated files to visitors.
Whenever an administrator updates an article, the website must be built again so that the generated output includes the changes.
Installing Hugo on Ubuntu
Before creating a website, we need to install Hugo on the Ubuntu server or development machine.
First, update the package list:
sudo apt update
Install Hugo:
sudo apt install hugo -y
Install Git as well. It is useful for downloading and managing Hugo themes.
sudo apt install git -y
Check whether Hugo is installed successfully:
hugo version
This command displays the installed Hugo version.
Note: Ubuntu repository packages may not always provide the latest Hugo release. If you need a newer version, use the installation method recommended in the official Hugo documentation.
Creating a New Hugo Website
After installing Hugo, create a new project.
Run:
hugo new project my-blog
This creates a directory named my-blog containing the basic Hugo project structure.
Move into the project directory:
cd my-blog
Initialize Git:
git init
Git helps track changes to website content, configuration, and theme files.
Understanding the Project Structure
A newly created Hugo project contains directories and configuration files.
A typical structure looks like this:
my-blog/
│
├── archetypes/
│
├── assets/
│
├── content/
│
├── data/
│
├── layouts/
│
├── static/
│
├── themes/
│
└── hugo.toml
The main directories are:
| Directory or File | Purpose |
|---|---|
archetypes/ |
Default templates for new content |
assets/ |
Files processed by Hugo |
content/ |
Blog posts and website pages |
data/ |
Data files used by templates |
layouts/ |
Custom HTML templates |
static/ |
Files copied directly to the generated website |
themes/ |
Installed website themes |
hugo.toml |
Main website configuration |
The public/ directory is generated when Hugo builds the website.
Installing a Hugo Theme
A theme controls the design and layout of a Hugo website.
Hugo supports many themes, including themes designed for blogs, documentation, and business websites.
For this example, we will use the Ananke theme.
From the root of the project, run:
git submodule add https://github.com/gohugo-ananke/ananke themes/ananke
This downloads the theme into the themes/ananke directory.
Open the Hugo configuration file:
nano hugo.toml
Add the following configuration:
baseURL = "https://blog.example.com/"
languageCode = "en-us"
title = "My Blog"
theme = "ananke"
Replace blog.example.com with your actual website domain.
Save the file after making the changes.
The baseURL specifies the website’s public address, title defines the website name, and theme selects the installed theme.
Creating Your First Blog Post
One of the main advantages of Hugo is that blog posts can be created using Markdown files.
Create a new post:
hugo new content content/posts/first-post.md
This creates a Markdown file inside the content/posts/ directory.
Open the file:
nano content/posts/first-post.md
Add the following content:
---
title: "My First Blog Post"
date: 2026-11-18
draft: false
description: "This is my first blog post using Hugo."
tags:
- Hugo
- Blogging
categories:
- Tutorials
---
## Introduction
Welcome to my first blog post.
This website is created using Hugo without requiring a database.
Hugo converts Markdown content into static HTML pages.
## Why Hugo?
- Fast website generation
- No database required
- Easy content management
- Simple deployment
Save the file.
Understanding Markdown Front Matter
The information at the beginning of a Hugo content file is called front matter.
It contains metadata about the article.
| Field | Purpose |
|---|---|
title |
Defines the article title |
date |
Specifies the publication date |
draft |
Determines whether the article is a draft |
description |
Provides a short article description |
tags |
Adds tags to the article |
categories |
Organizes articles into categories |
When draft is set to true, Hugo normally excludes the article from production builds.
Set it to false when the article is ready to publish.
Previewing the Website Locally
Before publishing the website, Hugo provides a built-in development server.
Run:
hugo server
Hugo builds the website and starts a local development server.
The terminal displays a local address, usually:
http://localhost:1313/
Open this address in a browser to preview the website.
The development server watches for changes to content, templates, and other project files. It automatically rebuilds the preview when changes are detected.
To stop the server, press:
Ctrl + C
Important: The Hugo development server is intended for development and previewing. For production hosting, generate the static files and serve them through a web server such as Nginx.
Generating Static Website Files
After creating the website and checking the content, generate the production files.
From the root directory of the Hugo project, run:
hugo
Hugo processes the content and creates the generated website inside the public/ directory.
The output may look like this:
public/
│
├── categories/
│
├── posts/
│ ├── first-post/
│ │ └── index.html
│ │
│ └── index.html
│
├── tags/
│
├── index.html
├── index.xml
└── sitemap.xml
The exact output depends on the theme and website configuration.
The important point is that the public/ directory contains the files required to serve the website.
You do not need to install Hugo on the production server if you generate the website on another machine and upload the generated files.
Hosting a Hugo Website Using Nginx on Ubuntu
After generating the static website, we can use Nginx to serve it to visitors.
Nginx is a web server that can deliver HTML, CSS, JavaScript, images, and other static files.
Step 1: Install Nginx
On the Ubuntu server, update the package list:
sudo apt update
Install Nginx:
sudo apt install nginx -y
Start and enable the Nginx service:
sudo systemctl enable --now nginx
Check its status:
sudo systemctl status nginx
Step 2: Create a Website Directory
Create a directory where the generated Hugo files will be stored.
For this example, we will use:
sudo mkdir -p /var/www/blog
This directory will become the document root for the website.
Step 3: Upload the Generated Files
Build your Hugo website on your development machine:
hugo
Upload the contents of the generated public/ directory to the Ubuntu server’s website directory.
For example, using rsync from your local machine:
rsync -av --delete public/ user@SERVER_IP:/var/www/blog/
Replace:
userwith your Ubuntu server username.SERVER_IPwith your server’s IP address.
The command copies the generated files to the server. The --delete option removes files from the destination that are no longer present in the source directory. Use it only when the destination is dedicated to this generated website.
If you are using WinSCP, you can also upload the contents of public/ into /var/www/blog/.
Step 4: Set File Permissions
On the Ubuntu server, make sure Nginx can read the website files.
For a simple static website:
sudo chown -R root:www-data /var/www/blog
Set directory permissions:
sudo find /var/www/blog -type d -exec chmod 755 {} \;
Set file permissions:
sudo find /var/www/blog -type f -exec chmod 644 {} \;
These permissions allow Nginx to read the files while keeping them from being modified by ordinary web requests.
Step 5: Configure the Nginx Server Block
Create a configuration file for the Hugo website:
sudo nano /etc/nginx/sites-available/blog
Add the following configuration:
server {
listen 80;
listen [::]:80;
server_name blog.example.com www.blog.example.com;
root /var/www/blog;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Replace the example domain names with your actual domain.
Explanation:
listen 80tells Nginx to accept HTTP traffic on port 80.server_namespecifies the domain names handled by this server block.rootidentifies the directory containing the generated Hugo files.index index.htmlspecifies the default page.try_fileschecks whether the requested file or directory exists and returns a 404 response if it does not.
Step 6: Enable the Website
Create a symbolic link to enable the configuration:
sudo ln -s /etc/nginx/sites-available/blog /etc/nginx/sites-enabled/
Check the Nginx configuration:
sudo nginx -t
If the configuration test is successful, reload Nginx:
sudo systemctl reload nginx
Step 7: Configure DNS
To make the website accessible using a domain name, configure the domain’s DNS records.
For example:
| Record Type | Name | Value |
|---|---|---|
| A | blog |
Your server’s public IPv4 address |
| A | www.blog |
Your server’s public IPv4 address |
The DNS records must point to the correct server address.
After DNS changes have propagated, visitors can open:
http://blog.example.com
For production websites, configure HTTPS using a valid TLS certificate.
Updating Blog Posts
One of the benefits of Hugo is that updating content does not require database operations.
Whenever you want to publish a new article:
- Create a new Markdown file inside the
content/posts/directory. - Add the article title, date, description, and content.
- Set
draft: falsewhen the article is ready. - Run the Hugo build command.
- Upload the newly generated files to the web server.
For example:
hugo new content content/posts/nginx-tutorial.md
After editing the article, generate the website again:
hugo
Then upload the updated public/ directory to the server.
Nginx does not need to be restarted every time a blog post is updated. It can serve the updated files directly.
Important Things to Understand
Although Hugo does not require a database for a basic blog, it is important to understand a few limitations.
- No built-in database: Hugo stores content in files rather than a database.
- No automatic admin dashboard: Content is generally created and edited using Markdown files and a text editor.
- Rebuilding is required: Changes must be generated into the
public/directory before they appear on the production website. - No built-in user authentication: Features such as user accounts and private dashboards require additional services or application logic.
- Forms need additional services: Contact forms, comments, and other interactive features may require an external service or a separate backend.
Hugo can still be combined with APIs and external services when a website needs additional functionality.
Conclusion
Hugo is a useful solution for creating and hosting websites without a database. It allows administrators to manage blog content using Markdown files and generate complete static websites.
By combining Hugo with Nginx on Ubuntu, you can create a simple and efficient publishing workflow. Hugo handles content generation, while Nginx delivers the generated files to website visitors.
This approach is especially suitable for company blogs, documentation websites, portfolios, and other content-focused websites that do not require database-driven functionality.