Self-hosting
Deploy NoteGen Server with Docker Compose, then configure HTTPS, initialize the instance, connect clients, and maintain it.
NoteGen Server provides accounts, device pairing, realtime sync, team collaboration, and account administration for NoteGen. This guide is for users running an experimental instance on their own Linux server or trusted local network.
To use the beta service run by NoteGen, see Use NoteGen Official Sync.
NoteGen Server is experimental. Deployment, configuration, and database structures may change. Always keep your local NoteGen Markdown files and never treat an experimental instance as the only copy of important data.
Choose a deployment method
| Method | Best for | Requirements |
|---|---|---|
| Docker Compose (recommended) | Quick trials and personal or small-team instances | Docker Engine and Docker Compose v2 |
| Run from source | Reading the implementation, debugging the protocol, and contributing | Node.js 22+, pnpm 10.20.0, and PostgreSQL 17 |
Use Docker Compose for production-like or long-running experiments. Source mode is primarily for development; do not expose pnpm dev directly as a production service.
Deploy with Docker Compose
The default Compose stack starts NoteGen Server and PostgreSQL 17. Two separate volumes store the database and attachments. The service listens only on 127.0.0.1:3789 on the host by default.
The official test image is ghcr.io/codexu/note-gen-server:beta. It supports linux/amd64 and linux/arm64 and can be pulled anonymously. The host does not need Node.js, pnpm, or a source build. The beta tag points to the most recently published test release; this guide uses that channel for deployment and upgrades.
1. Prepare the server
Before starting, confirm that:
- Docker Engine and Docker Compose v2 are installed;
- the server can access
ghcr.io; - remote deployments have a domain pointed at the server;
- the firewall exposes only SSH, HTTP, and HTTPS, never PostgreSQL.
2. Download the deployment configuration
git clone https://github.com/codexu/note-gen-server.git
cd note-gen-server
cp .env.docker.example .envcompose.yaml defines the deployment topology. .env contains configuration for this instance. Never commit the real .env file to Git.
3. Configure environment variables
Run this command three times to generate three different random values:
openssl rand -hex 32Edit .env and verify at least these values:
| Variable | Value |
|---|---|
POSTGRES_PASSWORD | The first random value, used only by this PostgreSQL instance |
AUTH_SECRET | The second random value; do not casually rotate it after launch |
SETUP_TOKEN | The third random value, entered in the installer; never put it in URLs, screenshots, or public logs |
PUBLIC_BASE_URL | The exact address used by NoteGen clients, without a path or trailing slash |
SERVER_BIND_ADDRESS | Keep 127.0.0.1 and expose the service through a reverse proxy |
NOTEGEN_SERVER_IMAGE | Change to ghcr.io/codexu/note-gen-server:beta to follow the test release channel |
ACCOUNT_STORAGE_MAX_BYTES | Initial per-account sync capacity, 5 GiB by default, including retained history and upload reservations |
INSTANCE_STORAGE_MAX_BYTES | Initial instance sync capacity, 50 GiB by default; monitor database indexes, WAL, and backups separately |
STORAGE_MIN_FREE_BYTES | Minimum free space on the blob filesystem, 1 GiB by default |
Set the image in .env to the following value, even if the example file uses a specific version:
NOTEGEN_SERVER_IMAGE=ghcr.io/codexu/note-gen-server:betaTo control which version you deploy, replace beta with a published full version tag, or pin a digest using ghcr.io/codexu/note-gen-server@sha256:....
For a local-only trial:
PUBLIC_BASE_URL=http://127.0.0.1:3789Remote deployments must use HTTPS:
PUBLIC_BASE_URL=https://sync.example.com4. Start the services
docker compose pull
docker compose up -d
docker compose psThese commands pull the prebuilt image specified in .env and start the server, account portal, and PostgreSQL. For local container builds, see Run from source.
On first startup, the server waits for PostgreSQL and applies pending database migrations. Once both services report healthy, check readiness:
curl --fail http://127.0.0.1:3789/health/readyA successful response means the containers and database can accept requests. If readiness fails, start with Troubleshooting.
5. Configure HTTPS
Remote access requires Caddy, Nginx, or Traefik in front of NoteGen Server. The proxy must support:
- WebSocket Upgrade;
- the
Authorization,Range, andX-Request-Idheaders; - request bodies larger than an attachment part;
- streaming responses from
/v1/sync/eventswithout response buffering.
Minimal Caddy configuration:
sync.example.com {
reverse_proxy 127.0.0.1:3789
}Caddy obtains and renews HTTPS certificates automatically. Before exposing the service, configure an independent random SETUP_TOKEN: only its holder can create the first administrator. Continue after the page opens at https://sync.example.com.
Set TRUST_PROXY=true only when the proxy and containers are on a trusted network and external traffic cannot bypass the proxy to reach the server port directly.
6. Initialize the instance
Open PUBLIC_BASE_URL in a browser and follow the installer to:
- enter the
SETUP_TOKENfrom.env; - choose an instance name and create the first administrator;
- sign in and confirm that installation is closed;
- keep registration disabled or use invitations for test members.
After installation, you can remove SETUP_TOKEN from .env. This does not reopen the installer. Existing installations do not need an installation token when upgrading.
Public registration increases moderation and maintenance work. Keep personal instances closed and create time-limited invitations when another user needs access.
7. Connect NoteGen
Under Settings → Sync → NoteGen Sync → Self-hosted server, enter the exact PUBLIC_BASE_URL. Follow the instance's registration process to get an account, then sign in, link a workspace, and confirm the sync scope. See Connect to a self-hosted NoteGen service for the client steps.
Validate the connection in this order:
- create a test note on device A;
- confirm that device B receives it;
- briefly take one device offline and edit the test content on both devices;
- reconnect and confirm sync continues while local Markdown remains available.
See Sync for other sync options.
Storage capacity
Administrators can change the per-account and instance capacity limits in GiB under the Web administration portal’s instance operations → access and configuration → runtime configuration. Enter the current password and save to apply the limits immediately without restarting. Decimal values are supported, with a minimum of 1 MiB.
ACCOUNT_STORAGE_MAX_BYTES and INSTANCE_STORAGE_MAX_BYTES provide initial values at first installation or for older instances without saved capacity settings. Once saved in the portal, database settings take precedence and are not overwritten by environment variables on restart.
Capacity includes retained history and attachment upload reservations. Shared libraries count toward their owner’s account. Lowering a limit does not delete existing data; when usage exceeds the limit, additional usage is restricted while reads, deletions, and upload cancellation remain available. Deleting a note does not immediately reclaim all capacity. Reserve separate disk space for database indexes, WAL, and backups.
Upgrade the instance
Before upgrading, review the new release notes and create a consistent backup of PostgreSQL and attachments. When using the beta channel, run the following commands to pull and apply the most recently published test release without changing the image tag each time. Keep existing passwords, keys, and instance URLs in .env; do not overwrite it with the example file.
cd note-gen-server
git pull --ff-only
docker compose pull
docker compose up -d
docker compose psDatabase migrations run during service startup. Recheck the instance after an upgrade:
curl --fail http://127.0.0.1:3789/health/ready
docker compose logs --tail=200 serverPublishing a new test release does not automatically update running containers; run docker compose pull and docker compose up -d to apply it. If you pin a full version or digest, update NOTEGEN_SERVER_IMAGE in .env before upgrading. If database migrations have run, follow the Backup and restore runbook to restore the matching data before rolling back; switching to the old image alone is insufficient.
Data and backups
The default deployment stores two groups of data:
| Data | Default location |
|---|---|
| Accounts, devices, sync cursors, and object versions | Docker postgres_data volume |
| Attachments, blobs, and server-generated files | Docker notegen_data volume |
A backup must cover PostgreSQL and notegen_data at a consistent point in time, and recovery must be verified in an isolated environment. Backing up only one part is incomplete.
Filesystem deployments provide offline backup, signature verification, and restore into a new instance. Follow the repository Backup and restore runbook, and complete an isolated recovery before opening testing. Archives are currently unencrypted: restrict access and keep a separate off-host copy. The filesystem restore commands do not apply to S3.
Deploy one server replica. Storage budgets exclude database indexes, WAL, and backup directories, so disk monitoring is still required.
Stop containers while preserving data:
docker compose downDo not run docker compose down -v while the data is needed. -v requests deletion of the Compose-managed volumes.
Routine maintenance
Check container state and recent logs:
docker compose ps
docker compose logs --tail=200 server
docker compose logs --tail=200 postgresFollow server logs:
docker compose logs -f serverCheck readiness and advertised capabilities:
curl --fail http://127.0.0.1:3789/health/ready
curl --fail http://127.0.0.1:3789/v1/capabilitiesRun from source
Source mode is for debugging and contributions. Install Node.js 22 or newer, pnpm 10.20.0, and PostgreSQL 17, then run:
git clone https://github.com/codexu/note-gen-server.git
cd note-gen-server
createuser notegen
createdb -O notegen notegen
pnpm install
cp .env.example .env
pnpm devSet DATABASE_URL, AUTH_SECRET, the first-install SETUP_TOKEN, and PUBLIC_BASE_URL in .env. In development, the API listens on 3789 and the account portal on 3790 by default.
See the contribution guide in the NoteGen Server repository for project structure, change boundaries, and contribution checks.
Build a container from source
To validate local changes, prepare .env in the repository root. If it does not exist, copy .env.docker.example and fill in the instance configuration; otherwise, keep the existing file. Set NOTEGEN_SERVER_IMAGE=notegen-server:dev, then run:
docker compose -f compose.yaml -f compose.dev.yaml up -d --buildRun the command again after changing the source to rebuild the image. Record the Git commit SHA when you need to reproduce a build.
Troubleshooting
| Symptom | Check and action |
|---|---|
| Image pull fails | Confirm access to ghcr.io, then check proxy and DNS settings |
| PostgreSQL never becomes healthy | Inspect docker compose logs --tail=200 postgres, free disk space, and POSTGRES_PASSWORD |
| Server never becomes healthy | Inspect server logs and confirm PostgreSQL is ready and required .env values are set |
| Browser works but the client cannot connect | Match the client address exactly to PUBLIC_BASE_URL and validate the HTTPS certificate |
| Realtime sync does not trigger | Confirm the reverse proxy supports WebSocket Upgrade |
| Attachment upload returns 413 | Increase the reverse proxy request-body limit |
| Sign-in fails after restart | Confirm AUTH_SECRET was not changed and the server clock is correct |
When opening an issue, include the operating system and CPU architecture, deployment method, image tag, reverse proxy, reproduction steps, and redacted container logs. Never publish .env, tokens, passwords, or recovery keys.
Deployment checklist
POSTGRES_PASSWORDandAUTH_SECRETare different random values;PUBLIC_BASE_URLexactly matches the address used by clients;- public access uses a valid HTTPS certificate;
- PostgreSQL and internal service ports are not directly exposed;
- the reverse proxy supports WebSocket and large attachment requests;
- PostgreSQL and attachment data have a coordinated backup;
- local Markdown is retained and at least one multi-device sync check has passed.