Use Docker Compose to Deploy the LobeChat Server Database Version
Introduction
By default, LobeChat uses IndexedDB to store user data, meaning the data is stored locally in the browser. Consequently, it becomes impossible to synchronize across multiple devices and poses a risk of data loss. Meanwhile, there is a server database version of LobeChat that addresses these issues and also allows for knowledge base functionality.
However, configuring the LobeChat DB version isn’t straightforward. It involves several parts: setting up the database, configuring authentication services, and configuring S3 storage1.
Configuring Logto
I recommend deploying the Logto service separately to potentially use it in other projects and manage them independently.
First, create a directory and enter it:
|
|
Here is my docker-compose.yaml
file for reference. Modify the relevant parts according to your own setup.
|
|
After modifying, write the docker-compose.yaml
file. Then start the container:
|
|
Warning
Don’t forget to set X-Forwarded-Proto
header in Nginx!
this proxy must support HTTPS because all of Logto’s APIs must be run in a secure environment, otherwise errors will occur2. Additionally, just having HTTPS isn’t enough; you also need to set the X-Forwarded-Proto
header value to https
to inform Logto that users are accessing it via HTTPS. I use Nginx as my reverse proxy service and provide a reference configuration below (modify according to your situation).
|
|
If you are manually configuring your Nginx configuration file rather than using a graphical tool like Nginx Proxy Manager, you need to complete other parts on your own (do not directly copy). In other words, if you use Nginx Proxy Manager, you can modify the proxy_pass
and then directly input it into the Advanced settings of the corresponding reverse proxy.
Afterwards, you can access the ADMIN_ENDPOINT to complete registration and configuration (the first registered account will automatically become an admin), remember to add an Application (prepare for LobeChat DB version installation), with a type selected as Next.js (App Router). Several key parameters should not be written incorrectly (replace domain names with your own LobeChat DB instance):
Redirect URIs
writehttps://lobe.example.com/api/auth/callback/logto
Post sign-out redirect URIs
writehttps://lobe.example.com/
CORS allowed origins
writehttps://lobe.example.com
There are three parameters that we will use when configuring the LobeChat DB version: Issuer endpoint, App ID, and App secrets (add one). Note them down.
You can also visit the /demo-app
path of your user ENDPOINT to test login and registration functions. If everything is fine, then Logto should be properly configured, allowing you to proceed with further steps.
Configuring MinIO
I recommend deploying MinIO separately for potential use in other projects as well.
Create a directory and enter it:
|
|
Here is my docker-compose.yaml
file for reference:
|
|
After modifying, write the docker-compose.yaml
file. Then start the container:
|
|
Subsequently, log into your MinIO instance from your MINIO_BROWSER_REDIRECT_URL, create a Bucket (e.g., name it as lobe
; if you change this, remember to modify corresponding configuration files), and configure an Access Policy similar to the following JSON file:
|
|
Then go to Access Keys and create a token, save these values as they will be used in the LobeChat DB version configuration.
Configuring LobeChat DB Version
Now we start configuring the LobeChat DB version. First, create a directory and enter it:
|
|
Here is my docker-compose.yaml
file for reference; remember to modify according to your setup:
|
|
For security reasons, KEY_VAULTS_SECRET
and NEXT_AUTH_SECRET
should be a random 32-character string. You can generate it using the command openssl rand -base64 32
.
Then modify domain names in environment variables to your own setup. Additionally, several Logto values need to be set:
Issuer endpoint
corresponds toLOGTO_ISSUER
App ID
corresponds toLOGTO_CLIENT_ID
App secrets
corresponds toLOGTO_CLIENT_SECRET
These can all be found on the Application page you created.
For S3 configuration, also modify accordingly (e.g., S3_ENDPOINT
, S3_BUCKET
, S3_PUBLIC_DOMAIN
, S3_ACCESS_KEY_ID
, S3_SECRET_ACCESS_KEY
). As for S3_ENABLE_PATH_STYLE
, it is usually set to 1
. If your S3 provider uses virtual-host style, change this value to 0
.
Path-style and virtual-host are different ways of accessing buckets and objects in S3. The URL structure and domain name resolution differ:
Assuming your S3 provider’s domain is s3.example.net, bucket is mybucket, object is config.env, the specific differences are as follows:
- Path-style:
s3.example.net/mybucket/config.env
- Virtual-host:
mybucket.s3.example.net/config.env
Finally, configure your API-related content (optional). My configuration example uses OpenAI. If you do not set it up on the server side, users will need to enter their own keys in the frontend.
After modifying, write the docker-compose.yaml
file and start the container:
|
|
In theory, you can now access LobeChat DB version. Before deploying to production, carefully check for any security issues. If you have questions, feel free to comment.
Additional Content
Customizing Logto Login/Registration Options
On the Logto management page, there is a Sign-in experience section with various customization options such as enabling or disabling registration and using social media SSO. By default, the Sign-up identifier is Username; I recommend configuring SMTP in Connectors to change it to Email address so users can recover their passwords via email.
Enabling Dark Mode for Logto Login/Registration Pages
On the Logto management page, under Sign-in experience, check Enable dark mode to turn on dark mode.
Adding GitHub Login/Registration Options in Logto
In the Logto management page, go to Connectors and add GitHub under Social connectors. Other options are similar.
Configuring Additional Models
LobeChat supports many models; you can set different environment variables to enable them. See the official documentation for OPENAI_MODEL_LIST
configuration options and explanations here. There are also other model provider options like DeepSeek.
You can retrieve Model List via API on the frontend to select needed models.
References
- Deploying Server-Side Database for LobeChat
- bug: use docker deploy logto v1.6 will always redirect to /unknown-session #4279
- Deployment | Logto docs #reverse-proxy
- Deploying LobeChat Server Database with Docker Compose
- LobeChat Model Service Providers - Environment Variables and Configuration #openai-model-list
-
See official documentation https://lobehub.com/en/docs/self-hosting/server-database ↩︎
-
Discussion on errors https://github.com/logto-io/logto/issues/4279 ↩︎
Related Content
- Migrate the Docker-Deployed Umami From One Server to Another.
- Deploying a Full-Stack Excalidraw Using Docker
- Config VLESS Protocol With Advance Feature in Sing-Box
- Netcup VServer (ARM64) Benchmark and Review
- Create MCQs With ChatGPT in Scales