Skip to content

Self-hosting

You can deploy Nya AI on your own server for complete control over your data and costs.

We recommend using Docker Compose for deployment. You can refer to the docker-compose.example.yml for the compose file.

Architecture Overview

Core Components:

  • db: Postgres 18 with the zhparser extension as the database
  • server: Nya AI's API backend, the core of the entire architecture, based on bun
  • web: Provides static resources for the frontend and acts as a reverse proxy, based on caddy
  • zero-cache: Sync engine for handling client data queries and mutation requests

Other Dependencies:

  • S3 Object Storage: Any S3-compatible object storage service
  • SearXNG: A metasearch engine used for the web search feature. The SearXNG instance must allow JSON formatted search requests

Environment Variables

Here are the main environment variables for nyaai-server:

Variable NameRequiredDescription
SITE_NAMEYesSite Name
FRONT_URLYesPublic URL of the user frontend (e.g., https://example.com)
ADMIN_URLYesPublic URL of the admin panel (e.g., https://admin.example.com)
BETTER_AUTH_SECRETYesBetter Auth encryption secret. Please use a long random string
DATABASE_URLYesPostgreSQL connection string
S3_ACCESS_KEY_IDYesS3-compatible storage access key ID
S3_SECRET_ACCESS_KEYYesS3-compatible storage secret access key
S3_ENDPOINTYesS3-compatible storage endpoint, e.g., s3.<region>.backblazeb2.com
S3_BUCKETYesName of the S3-compatible storage bucket
SEARXNG_URLYesURL of the SearXNG instance used for web search
OPENAI_BASE_URLNoBase URL of OpenAI-compatible providers, required if configuring platform models
OPENAI_API_KEYNoAPI Key of the OpenAI-compatible provider
SMTP_USER, SMTP_PASSWORD, SMTP_HOST, SMTP_FROM, SMTP_PORT, SMTP_SECURENoSMTP-related variables. Required if sending verification emails or password reset emails
REQUIRE_EMAIL_VERIFICATIONNoSet to true to mandate email address verification
GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRETNoGoogle OAuth-related variables. Required for Google OAuth login
GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRETNoGitHub OAuth-related variables. Required for GitHub OAuth login
STRIPE_SECRET_KEYNoStripe API key. Required if using Stripe for payments
STRIPE_WEBHOOK_SECRETNoStripe Webhook secret. Required if using Stripe for payments

Quick Start

After configuring docker-compose.yaml and the environment variables, run docker compose up -d to start the services.

Nya AI exposes two ports externally:

  • 8080 from web: User frontend interface
  • 8081 from web: Admin panel interface

The first user to log in to the admin panel automatically gains administrator privileges. For security reasons, it's recommended not to expose the admin port to the public network.