Static Site Generation with Hugo and Nginx is a common requirement for VPS administrators. This guide provides practical instructions that you can follow on Ubuntu 22.04/24.04 or Debian 12, though most steps apply to other distributions as well.
Prerequisites
- Basic familiarity with the Linux command line
- Root or sudo access to the server
- A registered domain name (for public-facing services)
- A web server with PHP (if applicable)
- A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
Installation Guide
Before making changes to the configuration, always create a backup of the existing files. This ensures you can quickly roll back if something goes wrong during the setup process.
# Install dependencies for CMS
sudo apt update
sudo apt install -y nginx mysql-server php-fpm php-mysql php-xml php-mbstring php-curl php-gd
# Download and install
cd /var/www
sudo wget https://example.com/hugo-latest.tar.gz
sudo tar xzf hugo-latest.tar.gz
sudo chown -R www-data:www-data /var/www/hugo
These commands should be run as root or with sudo privileges. If you're using a non-root user, prefix each command with sudo.
Database Configuration
Before making changes to the configuration, always create a backup of the existing files. This ensures you can quickly roll back if something goes wrong during the setup process.
# Create database for the CMS
sudo mysql -e "CREATE DATABASE hugo_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE USER 'hugo'@'localhost' IDENTIFIED BY 'secure_password';"
sudo mysql -e "GRANT ALL PRIVILEGES ON hugo_db.* TO 'hugo'@'localhost';"
sudo mysql -e "FLUSH PRIVILEGES;"
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
Configuration Options
When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.
Theme and Plugin Setup
If you encounter issues during setup, check the system logs first. Most problems can be diagnosed by examining the output of journalctl or the application-specific log files in /var/log/.
# Install dependencies for CMS
sudo apt update
sudo apt install -y nginx mysql-server php-fpm php-mysql php-xml php-mbstring php-curl php-gd
# Download and install
cd /var/www
sudo wget https://example.com/hugo-latest.tar.gz
sudo tar xzf hugo-latest.tar.gz
sudo chown -R www-data:www-data /var/www/hugo
Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.
Configuration Options
Regular maintenance is essential for keeping your hugo installation running smoothly. Schedule periodic reviews of log files, disk usage, and security updates to prevent issues before they occur.
Common Issues and Solutions
- Permission denied errors: Ensure files and directories have the correct ownership. Use
chown -Rto fix ownership andchmodfor permissions. - Service won't start: Check the logs with
journalctl -xe -u hugo. Common causes include port conflicts, missing configuration files, or insufficient permissions. - Connection timeout: Verify your firewall rules allow traffic on the required ports. Use
ss -tlnpto confirm the service is listening on the expected port.
Wrapping Up
Following this guide, your hugo setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.