---
title: "Self-Hosting HedgeDoc with Docker + Nginx + Let's Encrypt"
date: 2025-08-29
draft: false
tags: ["hedgedoc", "docker", "nginx", "letsencrypt", "self-hosting"]
categories: ["guides"]
cover:
  image: "/images/hedgedoc-cover.png"
  alt: "HedgeDoc collaborative editing"
  caption: "Collaborative Markdown editing with HedgeDoc"
  relative: true
  hidden: false
---

HedgeDoc is an open-source collaborative Markdown editor. Think *Google Docs for Markdown*: multiple people can edit the same note in real-time, with support for diagrams, math, polls, and slide decks. In this post we’ll walk through setting up your own instance on a server, secured with HTTPS.

---

## Prerequisites

- A Linux server with **Docker** and **Docker Compose**
- A domain name pointing to your server (e.g. `notes.alipourimjourneys.ir`)
- **Nginx** installed for reverse proxying
- **Certbot** for Let’s Encrypt certificates

---

## 1. Create the project directory

{{< highlight bash >}}
mkdir ~/hedgedoc && cd ~/hedgedoc
{{< /highlight >}}

---

## 2. Create `.env`

{{< highlight env >}}
POSTGRES_PASSWORD=ChangeThisStrongPassword
HD_DOMAIN=notes.alipourimjourneys.ir
{{< /highlight >}}

Generate a strong password with:

{{< highlight bash >}}
openssl rand -base64 32
{{< /highlight >}}

---

## 3. Create `docker-compose.yml`

{{< highlight yaml >}}
version: "3.9"

services:
  db:
    image: postgres:16
    environment:
      POSTGRES_USER: hedgedoc
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: hedgedoc
    volumes:
      - db:/var/lib/postgresql/data
    restart: unless-stopped

  hedgedoc:
    image: quay.io/hedgedoc/hedgedoc:1.10.2
    depends_on:
      - db
    environment:
      CMD_DB_URL: postgres://hedgedoc:${POSTGRES_PASSWORD}@db:5432/hedgedoc
      CMD_DOMAIN: ${HD_DOMAIN}
      CMD_PROTOCOL_USESSL: "true"
      CMD_URL_ADDPORT: "false"
      CMD_PORT: "3000"
      CMD_EMAIL: "true"
      CMD_ALLOW_EMAIL_REGISTER: "false"
    volumes:
      - uploads:/hedgedoc/public/uploads
    ports:
      - "127.0.0.1:3000:3000"
    restart: unless-stopped

volumes:
  db:
  uploads:
{{< /highlight >}}

Bring it up:

{{< highlight bash >}}
docker compose up -d
{{< /highlight >}}

---

## 4. Get a Let’s Encrypt certificate

Request a cert with a **DNS challenge**:

{{< highlight bash >}}
sudo certbot certonly   --manual   --preferred-challenges dns   -d notes.alipourimjourneys.ir   -m you@example.com   --agree-tos --no-eff-email
{{< /highlight >}}

Add the TXT record certbot asks for, wait for DNS to propagate, then continue.  
Certificates will be in:

{{< highlight bash >}}
/etc/letsencrypt/live/notes.alipourimjourneys.ir/
{{< /highlight >}}

---

## 5. Configure Nginx

Create `/etc/nginx/sites-available/notes.alipourimjourneys.ir`:

{{< highlight nginx >}}
server {
  server_name notes.alipourimjourneys.ir;

  listen 80;
  listen [::]:80;
  return 301 https://$host$request_uri;
}

server {
  server_name notes.alipourimjourneys.ir;

  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  ssl_certificate     /etc/letsencrypt/live/notes.alipourimjourneys.ir/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/notes.alipourimjourneys.ir/privkey.pem;

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}
{{< /highlight >}}

Enable the config and reload Nginx:

{{< highlight bash >}}
sudo ln -s /etc/nginx/sites-available/notes.alipourimjourneys.ir /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
{{< /highlight >}}

---

## 6. Create users

Because we disabled self-registration, create accounts manually:

{{< highlight bash >}}
docker compose exec hedgedoc ./bin/manage_users --add alice@example.com
{{< /highlight >}}

You’ll be prompted for a password.  
To reset a password later:

{{< highlight bash >}}
docker compose exec hedgedoc ./bin/manage_users --reset alice@example.com
{{< /highlight >}}

---

## 7. Done!

Visit [https://notes.alipourimjourneys.ir](https://notes.alipourimjourneys.ir) and log in with the user you created. You now have your own collaborative Markdown editor 🎉

---

**Extras:**

- Backups: dump the PostgreSQL database and save the `uploads` volume.  
- Upgrades: `docker pull quay.io/hedgedoc/hedgedoc:latest && docker compose up -d`.  
- Integrations: HedgeDoc supports S3/MinIO image storage, GitHub/GitLab/Google login, and more.

---

{{< sigdl >}}
