Subdirectory Publishing with Docker and Hyvor Blogs

Last updated:

If you have a website with Docker and are thinking about adding a blog, you are on the right track. A blog is a great way to share updates, write about what you are building, and give your SEO a nice little boost.

When it comes to hosting a blog, you've got a few choices. Out of many options, hosting it under a subdirectory like yourwebsite.com/blog appears to be a good solution instead of spinning up a whole new subdomain.

Why? Because it keeps everything under one roof. Your branding stays tight, search engines love the shared domain, and you avoid the hassle of managing cookies and sessions across different subdomains.

In this article, I will walk you through how to host a Hyvor Blogs blog on a subdirectory while keeping your website running inside Docker. It is simpler than it sounds. By the end of this article, you will have a clean, containerized setup that serves both your website and your blog like a pro.

Set up Hyvor Blogs

First, you must create a blog and configure the basic settings for self-hosting.

Create a blog at the Hyvor Blogs Console. You will get a subdomain, which you need in a later step.

Configure hosting settings

  1. Go to Settings → Hosting.

  2. Select the Self-hosting option for Hosting at.

  3. Set the Self-hosting URL to the absolute URL of the subdirectory where you plan to host your blog. For example, https://yourwebsite.com/blog. You can customize the subdirectory part (/blog) if needed.

  4. Click Save.

Create a Delivery API key

  1. Go to Settings → API Keys.

  2. Click Create API Key.

  3. Select Delivery API as the API.

  4. Set a name, such as Docker App.

  5. Click Create.

You will need the API key in a later step.

Set up a webhook

  1. Go to Settings → Webhooks.

  2. Create a webhook with the following URL:

    your website URL + /hyvorblogs/webhook

    For example: https://yourwebsite.com/hyvorblogs/webhook

  3. Select the following events:

    • cache.single

    • cache.templates

    • cache.all

You will need the Webhook Secret in a later step.

Deliver the blog within a Docker container

Let’s dig deep into the technical part!

Hyvor Blogs has made it easy by providing an official Docker image that you can run right out of the box. This image is designed to serve your blog as a standalone service while keeping your blog in a subdirectory with a simple reverse proxy setup.

Under the hood, this Docker image uses the Hyvor Blogs Delivery API to fetch your blog content. When a page is requested for the first time, the content is retrieved from the API and cached. Subsequent requests to the same endpoint are served directly from the cache, delivering a much faster experience for your users.

First, include the Hyvor Blogs Docker image as another service in your docker-compose.yaml:

services:
hyvor-blogs:
image: hyvor/hyvor-blogs-docker
container_name: hyvor-blogs
environment:
- BLOG_SUBDOMAIN=your-blog
- BLOG_HOSTING_PATH=/blog
- BLOG_DELIVERY_API_KEY=your-api-key
- BLOG_WEBHOOK_SECRET=your-webhook-secret
ports:
- 8080:80

The next step is to set up a reverse proxy that routes requests from /blog on your main domain to the Hyvor Blogs container. Here are example configurations for three popular reverse proxies: Caddy, Nginx, and Traefik.

Caddy

If you're using Caddy, this simple config handles /blog/* and proxies it to the Hyvor Blogs container:

yourdomain.com {
handle /blog/* {
reverse_proxy localhost:8080
}
}

Nginx

For Nginx, this basic setup forwards all /blog/* traffic to the container:

server {
listen 80;
server_name yourdomain.com;
location /blog/ {
proxy_pass http://localhost:8080;
}
}

Traefik

With Traefik, you can configure routing using Docker labels like this:

services:
hyvor-blogs:
labels:
- "traefik.enable=true"
- "traefik.http.routers.hyvor-blogs.rule=PathPrefix(`/blog`)"
- "traefik.http.routers.hyvor-blogs.entrypoints=web"
- "traefik.http.services.hyvor-blogs.loadbalancer.server.port=80"

Deploying on Kubernetes

If you are running your app on a Kubernetes cluster, you can also deploy the Hyvor Blogs container just like any other service.

apiVersion: v1
kind: Service
metadata:
name: hyvor-blogs
spec:
selector:
app: hyvor-blogs
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hyvor-blogs
spec:
replicas: 1
selector:
matchLabels:
app: hyvor-blogs
template:
metadata:
labels:
app: hyvor-blogs
spec:
containers:
- name: hyvor-blogs
image: hyvor/hyvor-blogs-docker
env:
- name: BLOG_SUBDOMAIN
value: "your-blog"
- name: BLOG_HOSTING_PATH
value: "/blog"
- name: BLOG_DELIVERY_API_KEY
value: "your-api-key"
- name: BLOG_WEBHOOK_SECRET
value: "your-webhook-secret"
ports:
- containerPort: 80

And that’s it! Whether you’re running a simple Docker setup, using a reverse proxy, or managing a Kubernetes cluster, integrating a Hyvor Blog into your app under a subdirectory is super easy. With the official Docker image, solid caching, and flexible hosting options, you get the power of a fast, beautiful blog without the hassle of building one from scratch.

Hope this helped you get your blog up and running! Feel free to share if you run into any snags. Happy blogging!

Start publishing today

Join hundreds of publishers and businesses building with Hyvor Blogs.

14-day free trial
No credit card required
Cancel anytime