# Self-host AFFiNE

> A self-hostable workspace that combines documents, whiteboards and databases, with real-time collaboration, run as a Node.js server backed by PostgreSQL and Redis. Run your own AFFiNE on an always-on EnvHaven workspace by asking its coding agent: one request installs it, puts it on an HTTPS address and locks it down. What the agent takes care of, and the manual route.

_Updated November 23, 2026_

Running your own AFFiNE usually means a list of server chores: a machine that stays on, Docker or a runtime, a reverse proxy with certificates, a domain, and the settings that make AFFiNE behave behind all of it. On an EnvHaven workspace you skip the list. You ask the coding agent, and it does the work while you watch.

## Just ask your agent

Open a Plus workspace (AFFiNE runs in Docker, which Plus and Pro include), tap **Launch** to start any coding agent (Claude Code, Codex, OpenCode or another), and ask it:

```text
Set up AFFiNE on this workspace and give me the link. Follow https://envhaven.com/self-host/affine.md
```

Then open the link it sends and create your AFFiNE account straight away, before anyone else finds the address. That is the whole request: the address in it is this page's Markdown copy, and the agent follows the instructions for it further down, with every setting AFFiNE's docs require.

## Or keep it private with Tailscale

The preview URL puts AFFiNE on the public internet, which suits something other people need to reach. For an app only you and your household use, your tailnet is the better home: Tailscale gives AFFiNE an HTTPS address that only your own devices, signed in to your Tailscale account, can open. Save a Tailscale auth key in the workspace's **Vars** pane as `TS_AUTHKEY`, and ask the agent:

```text
Set up AFFiNE on my tailnet instead of the preview URL. Follow https://envhaven.com/self-host/affine.md and https://envhaven.com/guides/self-host-privately-with-tailscale.md
```

- A Tailscale container runs beside AFFiNE, so it keeps its private address through workspace restarts and updates, and every app you set up this way gets an address of its own.
- Anything other services have to reach, such as a webhook, still needs a public address. [Keep self-hosted apps private with Tailscale](https://envhaven.com/guides/self-host-privately-with-tailscale) covers both, and what Tailscale's free plan includes.

| At a glance |  |
| --- | --- |
| What it is | Notes, wikis and knowledge bases |
| License | MIT |
| Runs as | Docker (`ghcr.io/toeverything/affine:stable`) |
| Memory | 2 GB for basic usage; 4 GB if there will be docs with more than 10k words ([docs](https://docs.affine.pro/self-host-affine/)) |
| Plan that fits | Plus or larger |
| Web port | 3010 |
| Documentation | [docs.affine.pro/self-host-affine/](https://docs.affine.pro/self-host-affine/) |

## What your agent takes care of

- **Installing it.** AFFiNE runs from the official image, `ghcr.io/toeverything/affine:stable`, with its data in folders under `~/apps/affine`.
- **Putting it on an HTTPS address.** The workspace's preview URL serves it, and your own domain can too.
- **Locking it down first.** What AFFiNE's docs say to set before it faces the internet, below.
- **Telling you what to back up**: ./data/postgres (PostgreSQL data directory), ./data/storage (uploaded blobs, mounted at /root/.affine/storage) and ./config (config.json, mounted at /root/.affine/config) ([docs](https://docs.affine.pro/self-host-affine/install/docker-compose-recommended)).

### The settings it needs behind a proxy

- `server.externalUrl` in config/config.json (env alias `AFFINE_SERVER_EXTERNAL_URL`): Public base URL used to build invitation, share and public doc links; set it to the final HTTPS URL. ([docs](https://docs.affine.pro/self-host-affine/install/configuration))
- Admin panel: Settings -> Server -> external url: Second place to set the same external URL after the reverse proxy is in place. ([docs](https://docs.affine.pro/self-host-affine/administer/domain-and-https))
- `server.https` (env alias `AFFINE_SERVER_HTTPS`): Boolean telling the server it is served on an https domain; default false. ([docs](https://github.com/toeverything/AFFiNE/releases/latest/download/config.schema.json))
- `server.host` (env alias `AFFINE_SERVER_HOST`): FQDN the server is deployed at; default localhost. ([docs](https://github.com/toeverything/AFFiNE/releases/latest/download/config.schema.json))
- WebSocket upgrade on the reverse proxy: Sync and collaboration run over WebSocket, so the proxy must pass upgrades. ([docs](https://docs.affine.pro/self-host-affine/administer/domain-and-https))
- X-Forwarded-Proto and related proxy headers (no trusted-proxy setting is documented): The documented nginx example forwards these headers. ([docs](https://docs.affine.pro/self-host-affine/administer/domain-and-https))

### Before it faces the internet

- Whoever opens /admin first creates the administrator account, so do it before exposing the instance. ([docs](https://docs.affine.pro/self-host-affine/install/after-installation))
- The docs' production checklist asks for the admin account, a domain, HTTPS and the external URL before real users. ([docs](https://docs.affine.pro/self-host-affine/))
- The current compose file starts Postgres with trust authentication and no password; only the AFFiNE port is published, so do not publish the Postgres port. ([docs](https://github.com/toeverything/AFFiNE/releases/latest/download/docker-compose.yml))
- config.json can hold credentials such as SMTP settings; keep it private. ([docs](https://docs.affine.pro/self-host-affine/install/configuration))

## Things to ask next

Everything after the install is one more sentence to the agent. Some that come up:

- "Import this folder of Markdown notes, keeping the folder structure."
- "Turn off public sign-ups now that my account exists."
- "Move AFFiNE to app.example.com." Add the domain on the dashboard's Domains page with a CNAME to `domains.envhaven.app`, and the agent changes AFFiNE's address settings to match.
- "Update AFFiNE to the latest release." It pulls the new image and recreates the container, data kept.

## Instructions for the agent

The agent reads these from the page's Markdown copy. They also work pasted on their own, if you would rather give them in your own words.

```text
Set up AFFiNE on this workspace and serve it at my preview URL.
- Use Docker Compose with the official image, ghcr.io/toeverything/affine:stable, starting from the docs' compose file: https://github.com/toeverything/AFFiNE/releases/latest/download/docker-compose.yml. If `docker compose` is missing, install the Compose plugin into ~/.docker/cli-plugins first.
- The docs' setup includes: postgres (pgvector/pgvector:pg16); redis; affine_migration (one-time migration job using the same image).
- Keep the compose file in ~/apps/affine and all of its data in folders there (bind mounts, not named volumes), with restart: unless-stopped on every service.
- This server has no firewall, so publish no port on its public IP, and drop host networking and privileged mode from the docs' compose file. Docker runs on the host: connect this workspace to the compose network and relay my preview URL's port to AFFiNE's port 3010.
- The preview URL terminates HTTPS in front of AFFiNE: serve plain HTTP on its port, and trust the forwarded headers the relay passes on.
- Set what "The settings it needs behind a proxy" lists on https://envhaven.com/self-host/affine.md for the preview URL, as AFFiNE's docs describe for running behind a proxy; skip any that apply only when AFFiNE serves HTTPS itself.
- Before the preview URL serves it, apply what "Before it faces the internet" lists on https://envhaven.com/self-host/affine.md.
- When it answers at the preview URL, send me the link and tell me what to back up.
- If I asked for my tailnet instead of the preview URL, set AFFiNE up the same way but follow https://envhaven.com/guides/self-host-privately-with-tailscale.md for the network: no preview URL, no relay.
```

## What to know

- In Docker, AFFiNE's containers keep running when the workspace restarts or updates. The relay from the preview URL is a process in the workspace, so after a restart or an update, ask the agent to restore it.
- The docs' nginx example sets the request body cap to 100 MB, the same figure as Cloudflare's standard-plan limit, so anything larger fails at the tunnel; the docs give no server-side blob size figure. ([docs](https://docs.affine.pro/self-host-affine/administer/domain-and-https))
- The quota page says unlimited blob size is planned but a limitation still exists today, with no figure given. ([docs](https://docs.affine.pro/self-host-affine/features/basic-user-quota))
- Email is optional. Without SMTP the app works, but invitations and mention notifications are not emailed; an admin can generate a password reset link by hand. ([docs](https://docs.affine.pro/self-host-affine/administer/email-notifications))
- AI features need a user-supplied provider API key (no local model, no GPU); chat and writing need an OpenAI, Anthropic or Gemini key. ([docs](https://docs.affine.pro/self-host-affine/administer/ai))
- Self-hosted workspaces are capped at 10 users unless a paid Team license is bought. ([docs](https://docs.affine.pro/self-host-affine/features/basic-user-quota))
- The Team Plan license check calls AFFiNE's licensing service over the Internet. ([docs](https://docs.affine.pro/self-host-affine/features/team-license))
- Redis is required. ([docs](https://docs.affine.pro/self-host-affine/install/requirements))
- A workspace has one preview URL and one custom domain, both serving the same port, so it puts one app on a public address at a time.

## Without a workspace

The manual route, on a server you run:

1. Rent a Linux VPS, secure SSH, and create a user for the app.
2. Install Docker and write a compose file from the official image.
3. Put a reverse proxy in front (Caddy, nginx or Traefik), get certificates, and point a domain at the server.
4. Set the proxy settings listed above for that domain, and pass WebSocket upgrades through the proxy if the app uses them.
5. Keep the firewall closed except for the proxy, and schedule backups and updates.

AFFiNE's own [documentation](https://docs.affine.pro/self-host-affine/) covers each step for its install methods.

## Sources

Facts about AFFiNE come from its own documentation, checked on 2026-11-23:

- [docs.affine.pro/self-host-affine](https://docs.affine.pro/self-host-affine/)
- [docs.affine.pro/self-host-affine/install/docker-compose-recommended](https://docs.affine.pro/self-host-affine/install/docker-compose-recommended)
- [docs.affine.pro/self-host-affine/install/configuration](https://docs.affine.pro/self-host-affine/install/configuration)
- [docs.affine.pro/self-host-affine/administer/domain-and-https](https://docs.affine.pro/self-host-affine/administer/domain-and-https)
- [github.com/toeverything/AFFiNE/releases/latest/download/config.schema.json](https://github.com/toeverything/AFFiNE/releases/latest/download/config.schema.json)
- [docs.affine.pro/self-host-affine/features/basic-user-quota](https://docs.affine.pro/self-host-affine/features/basic-user-quota)
- [docs.affine.pro/self-host-affine/administer/email-notifications](https://docs.affine.pro/self-host-affine/administer/email-notifications)
- [docs.affine.pro/self-host-affine/administer/ai](https://docs.affine.pro/self-host-affine/administer/ai)
- [docs.affine.pro/self-host-affine/features/team-license](https://docs.affine.pro/self-host-affine/features/team-license)
- [docs.affine.pro/self-host-affine/install/requirements](https://docs.affine.pro/self-host-affine/install/requirements)
- [docs.affine.pro/self-host-affine/install/after-installation](https://docs.affine.pro/self-host-affine/install/after-installation)
- [github.com/toeverything/AFFiNE/releases/latest/download/docker-compose.yml](https://github.com/toeverything/AFFiNE/releases/latest/download/docker-compose.yml)

## Keep reading

- [Self-host any app with your agent](https://envhaven.com/self-host)
- [Self-host Memos](https://envhaven.com/self-host/memos)
- [Self-host SiYuan](https://envhaven.com/self-host/siyuan)
- [Self-host Trilium Notes](https://envhaven.com/self-host/trilium)
- [Self-host Docmost](https://envhaven.com/self-host/docmost)
- [AI agent hosting](https://envhaven.com/guides/ai-agent-hosting)

Source: https://envhaven.com/self-host/affine
