Environment Variables

This page explains the main environment variables used by self-hosted AFFiNE. Docker Compose users should set persistent paths and database credentials before the first start, because changing them after data exists can require a backup-and-restore workflow.

Docker Compose

VariableDescriptionDefault
AFFINE_REVISIONThe AFFiNE revision to deploy. Available values are stable, beta, and canary.stable
DB_DATA_LOCATIONLocation of the Postgres data directory to persist.
UPLOAD_LOCATIONLocation of uploaded blobs, such as images and files, to persist.
CONFIG_LOCATIONLocation of user custom configuration files to persist.

Server

VariableDescriptionDefault
AFFINE_PRIVATE_KEYPrivate key used by the crypto module to create signed tokens or encrypt data. If not provided, AFFiNE auto-generates one under CONFIG_LOCATION on first start.
AFFINE_SERVER_HTTPSWhether the server is hosted on an SSL/TLS-enabled domain.false
AFFINE_SERVER_HOSTFully qualified domain name where the server is deployed.localhost
AFFINE_SERVER_PORTPort the server listens on inside the container.3010
AFFINE_SERVER_SUB_PATHSubpath where the server is deployed, if any.
AFFINE_SERVER_EXTERNAL_URLBase URL of the AFFiNE server, used for generating external links.
Defaults to [server.protocol]://[server.host][:server.port] if not specified.

For production, configure Domain and HTTPS and make sure generated invitation links and public doc links use the correct external URL.

Database (Postgres)

VariableDescriptionDefault
DATABASE_URLDatabase URL passed to the server if you are not using Docker Compose.
DB_USERNAMEDatabase user.affine
DB_PASSWORDDatabase password. Docker Compose users should set a strong password before the first start to initialize Postgres safely.
DB_DATABASEDatabase name.affine
WARNING

Set DB_PASSWORD before your first Docker Compose start. Using POSTGRES_HOST_AUTH_METHOD=trust disables password authentication and should only be used in controlled local or test environments.

Redis

VariableDescriptionDefault
REDIS_SERVER_HOSTRedis host.localhost
REDIS_SERVER_PORTRedis port.6379
REDIS_SERVER_USERNAMERedis username.
REDIS_SERVER_PASSWORDRedis password.
REDIS_SERVER_DATABASERedis database index used by AFFiNE. If n is set as REDIS_SERVER_DATABASE, AFFiNE uses databases from n to n+4 for different purposes.0

Email

VariableDescriptionDefault
MAILER_HOSTHost of the email server, such as smtp.gmail.com.
MAILER_PORTPort of the email server. Common ports are 25, 465, and 587.465
MAILER_USERUsername used to authenticate with the email server.
MAILER_PASSWORDPassword used to authenticate with the email server.
MAILER_SENDERSender of all emails, for example AFFiNE Team <[email protected]>.
MAILER_IGNORE_TLSWhether to ignore the email server TLS certificate verification. Enable only for self-signed certificates you trust.

*You need an app password for services like Gmail: Source1, Source2.