HUGO

  • News
  • Docs
  • Themes
  • Community
  • GitHub
Star

What's on this Page

    • Before You Begin
    • What You’ll Need
      • Before We Begin
        • Connect a Host Account
        • Launch a New Application on Nanobox
    • Getting Started
      • Configure Hugo to run with Nanobox
      • Installing Hugo
      • Generating a New Hugo App
      • Install a theme
      • View Your App
      • Develop, Develop, Develop
    • Deploying Hugo with Nanobox
      • Stage Your Application (optional)
      • Deploy Your Application
HOSTING AND DEPLOYMENT

Host-Agnostic Deploys with Nanobox

Easily deploy Hugo to AWS, DigitalOcean, Google, Azure, and more…

hugo with nanobox

Before You Begin

Nanobox provides an entire end-to-end workflow for developing and deploying applications. Using Nanobox to deploy also means you’ll use it to develop your application.

If you’re already using Nanobox and just need deployment instructions, you can skip to Deploying Hugo with Nanobox

What You’ll Need

With Nanobox you don’t need to worry about having Golang or Hugo installed. They’ll be installed as part of the development environment created for you.

To get started you’ll just need the following three items:

  • A Nanobox Account - Signup is free
  • Nanobox Desktop - The free desktop development tool
  • An account with a hosting provider such as:
    • AWS
    • DigitalOcean
    • Linode
    • Azure (coming)
    • Google (coming)
    • Roll Your Own

Before We Begin

There are a few things to get out of the way before diving into the guide. To deploy, you’ll need to make sure you have connected a host account to your Nanobox account, and launched a new application.

Connect a Host Account

Nanobox lets you choose where to host your application (AWS, DigitalOcean, Google, Azure, etc.). In the Hosting Accounts section of your Nanobox dashboard link your Nanobox account with your host.

Launch a New Application on Nanobox

Launching a new app on Nanobox is very simple. Navigate to Launch New App in the dashboard, and follow the steps there. You’ll be asked to name your app, and select a host and region.

With those out of the way you’re ready to get started!

Getting Started

If you already have a functioning Hugo app, you can skip to Configure Hugo to run with Nanobox

To get started, all you’ll need an empty project directory. Create a directory wherever you want your application to live and cd into it:

mkdir path/to/project && cd path/to/project

Configure Hugo to run with Nanobox

Nanobox uses a simple config file known as a boxfile.yml to describe your application’s infrastructure. In the root of your project add the following boxfile.yml:

boxfile.yml

run.config:

  # use the static engine
  engine: static
  engine.config:

    # tell the engine where to serve static assets from
    rel_dir: public

  # enable file watching for live reload
  fs_watch: true

  # install hugo
  extra_steps:
    - bash ./install.sh

deploy.config:

  # generate site on deploy
  extra_steps:
    - hugo

If you already have a functioning Hugo app, which should now be configured, you can skip to Deploying Hugo with Nanobox.

Installing Hugo

Nanobox uses Docker to create instant, isolated, development environments. Because of this, you’ll need to make sure that during development you have Hugo available.

Do this by add a custom install script at the root of your project that will install Hugo automatically for you:

install.sh


#!/bin/bash

if [[ ! -f /data/bin/hugo ]]; then
  cd /tmp
  wget https://github.com/gohugoio/hugo/releases/download/v0.25.1/hugo_0.25.1_Linux-64bit.tar.gz
  tar -xzf hugo_0.25.1_Linux-64bit.tar.gz
  mv hugo /data/bin/hugo
  cd -
  rm -rf /tmp/*
fi

If the install script fails during nanobox run you may need to make it executable with chmod +x install.sh

Generating a New Hugo App

You’ll generate your new application from inside a Nanobox console (this is why you don’t need to worry about having Golang or Hugo installed).

Run the following command to drop into a Nanobox console (inside the VM) where your codebase is mounted:

nanobox run

nanobox run

Once inside here use the following steps to create a new Hugo application:

# cd into the /tmp dir to create an app
cd /tmp

# generate the hugo app
hugo new site app

# cd back into the /app dir
cd -

# copy the generated app into the project
shopt -s dotglob
cp -a /tmp/app/* .

Install a theme

cd into the themes directory and clone the nanobox-hugo-theme repo:

cd themes
git clone https://github.com/sdomino/nanobox-hugo-theme

To use the theme either copy the entire config.toml that comes with the theme, or just add the theme to your existing config.toml

# copy the config.toml that comes with the theme
cp ./themes/nanobox-hugo-theme/config.toml config.toml

# or, add it to your existing config.toml
theme = "nanobox-hugo-theme"

It is not intended that you use the nanobox-hugo-theme as your actual theme. It’s simply a theme to start with and should be replaced.

View Your App

To view your application simply run the following command from a Nanobox console:

hugo server --bind="0.0.0.0" --baseUrl=$APP_IP

hugo server

With that you should be able to visit your app at the given IP:1313 address

You can add a custom DNS alias to make it easier to access your app. Run nanobox dns add local hugo.dev. After starting your server, visit your app at hugo.dev:1313

Develop, Develop, Develop

IMPORTANT: One issue we are aware of, and actively investigating, is livereload. Currently, livereload does not work when developing Hugo applications with Nanobox.

With Hugo installed you’re ready to go. Develop Hugo like you would normally (using all the generators, etc.). Once your app is ready to deploy, run hugo to generate your static assets and get ready to deploy!

Deploying Hugo with Nanobox

If you haven’t already, make sure to connect a hosting account to your Nanobox account, and launch a new application in the Dashboard.

To deploy your application to Nanobox you simply need to link your local codebase to an application you’ve created on Nanobox. That is done with the following command:

nanobox remote add <your-app-name>

You may be prompted to login using your Nanobox credentials at this time

Stage Your Application (optional)

Nanobox gives you the ability to simulate your production environment locally. While staging is optional it’s always recommended, so there’s no reason not to!

To stage your app simply run:

nanobox deploy dry-run

Now visit your application with the IP address provided.

nanobox deploy dry-run

Deploy Your Application

Once everything checks out and you’re ready to deploy, simply run:

nanobox deploy

Within minutes you’re Hugo app will be deployed to your host and humming along smoothly. That’s it!

See Also

  • Hosting on KeyCDN
  • Host on Bitbucket
  • Host on Netlify
  • Host on GitLab
  • Host on GitHub
  • About Hugo
    • Overview
    • Hugo Features
    • The Benefits of Static
    • Roadmap
    • License
  • Getting Started
    • Get Started Overview
    • Quick Start
    • Install Hugo
    • Basic Usage
    • Directory Structure
    • Configuration
  • Themes
    • Themes Overview
    • Install and Use Themes
    • Customize a Theme
    • Create a Theme
  • Content Management
    • Content Management Overview
    • Organization
    • Supported Content Formats
    • Front Matter
    • Shortcodes
    • Related Content
    • Sections
    • Types
    • Archetypes
    • Taxonomies
    • Summaries
    • Links and Cross References
    • URL Management
    • Menus
    • Table of Contents
    • Comments
    • Multilingual and i18n
    • Syntax Highlighting
  • Templates
    • Templates Overview
    • Introduction
    • Template Lookup Order
    • Custom Output Formats
    • Base Templates and Blocks
    • List Page Templates
    • Homepage Template
    • Section Templates
    • Taxonomy Templates
    • Single Page Templates
    • Content View Templates
    • Data Templates
    • Partial Templates
    • Shortcode Templates
    • Local File Templates
    • 404 Page
    • Menu Templates
    • Pagination
    • RSS Templates
    • Sitemap Template
    • Robots.txt
    • Internal Templates
    • Alternative Templating
    • Template Debugging
  • Functions
    • Functions Quick Reference
    • .AddDate
    • .Format
    • .Get
    • .GetPage
    • .Param
    • .Scratch
    • .Unix
    • Math
    • absLangURL
    • absURL
    • after
    • apply
    • base64
    • chomp
    • countrunes
    • countwords
    • dateFormat
    • default
    • delimit
    • dict
    • echoParam
    • emojify
    • eq
    • findRE
    • first
    • ge
    • getenv
    • gt
    • hasPrefix
    • highlight
    • htmlEscape
    • htmlUnescape
    • humanize
    • i18n
    • imageConfig
    • in
    • index
    • int
    • intersect
    • isset
    • jsonify
    • lang.NumFmt
    • last
    • le
    • lower
    • lt
    • markdownify
    • md5
    • ne
    • now
    • partialCached
    • plainify
    • pluralize
    • print
    • printf
    • println
    • querify
    • range
    • readDir
    • readFile
    • ref
    • relLangURL
    • relURL
    • relref
    • render
    • replace
    • replaceRE
    • safeCSS
    • safeHTML
    • safeHTMLAttr
    • safeJS
    • safeURL
    • seq
    • sha
    • shuffle
    • singularize
    • slice
    • slicestr
    • sort
    • split
    • string
    • strings.TrimLeft
    • strings.TrimPrefix
    • strings.TrimRight
    • strings.TrimSuffix
    • substr
    • time
    • title
    • trim
    • truncate
    • union
    • uniq
    • upper
    • urlize
    • urls.Parse
    • where
    • with
  • Variables
    • Variables Overview
    • Site Variables
    • Page Variables
    • Shortcode Variables
    • Taxonomy Variables
    • File Variables
    • Menu Variables
    • Hugo Variables
    • Git Variables
    • Sitemap Variables
  • CLI
  • Troubleshooting
    • Troubleshoot
    • Accented Characters in URLs
    • Build Performance
    • EOF Error
  • Tools
    • Developer Tools Overview
    • Migrations
    • Starter Kits
    • Frontends
    • Editor Plug-ins
    • Search
    • Other Projects
  • Hosting & Deployment
    • Hosting & Deployment Overview
    • Host-Agnostic Deploys with Nanobox
    • Host on Netlify
    • Host on Firebase
    • Host on GitHub
    • Host on GitLab
    • Host on Bitbucket
    • Deployment with Wercker
    • Deployment with Rsync
  • Contribute
    • Contribute to Hugo
    • Development
    • Documentation
    • Themes
“Host-Agnostic Deploys with Nanobox” was last updated: October 13, 2017: Initial commit (a48229f)
Improve this page
By the Hugo Authors

The Hugo logos are copyright © Steve Francia 2013–2017.

The Hugo Gopher is based on an original work by Renée French.

  • File an Issue
  • Get Help
  • Discuss the Source Code
  • @GoHugoIO
  • @spf13
  • @bepsays
  • News
  • Docs
  • Themes
  • Community
  • GitHub
  • About Hugo
  • Getting Started
  • Themes
  • Content Management
  • Templates
  • Functions
  • Variables
  • CLI
  • Troubleshooting
  • Tools
  • Hosting & Deployment
  • Contribute