Detailed Deployment Tutorial Based on the Open-Source Large Language Model UI Framework: LobeChat
本文最后更新于 317 天前,其中的信息可能已经有所发展或是发生改变,如有失效可到评论区留言。
Article Abstract
To solve the needs of ChatGPT localized deployment and cross-device synchronization, the LobeChat server-side database version was chosen as the open-source large language model UI framework solution. This solution is based on PostgreSQL for vector database storage, MinIO for S3-compatible object storage, and Logto or GitHub for identity authentication, supporting multimodal dialogue and knowledge base interaction. During the deployment process, 5 domain names need to be configured, and reverse proxy and CORS policies must be set up, with a focus on resolving configuration issues such as Logto authentication callback exceptions. Ultimately, a localized large model dialogue system is achieved, suitable for enterprise scenarios requiring data privacy protection and multi-user collaboration, while also providing Docker deployment and GitHub alternative solutions to reduce configuration complexity.
Qwen3-14B · 2026-06-18

Preface

For ChatGPT, I had originally been using the app version on Mac because it has a free daily usage quota, which is more than enough for a light user like me and hard to exceed.

However, while researching the AI plugin ”AI Engine” on WordPress, I found that it only supports API usage and only supports the following providers:

image.png

After researching these providers for a while, I found that Azure's OpenAI can be used for free initially (the first month of registration comes with a $200 usage credit, and after that, it is billed on-demand monthly, meaning no charge if not used), so I went ahead and registered for one.

But thinking about it later, although using the free version of ChatGPT is basically enough, I can't rule out times when I might use it heavily in the future. At that time, Azure's OpenAI can be used as the main tool (after all, there is no monthly fee, you pay for what you use, on-demand billing, which is very suitable for a budget user like me). However, Azure's OpenAI only provides an API and has no client that can be used directly, which is very inconvenient. How to solve this problem? So I had to look for a solution among open-source large language model UI frameworks.

There are many open-source large language model UI frameworks: Hugging Face Transformers, DeepSpeed, FastChat, LangChain, GPT-NeoX, LobeHub, etc. Among them, the most suitable for general personal deployment is LobeHub, because of the following advantages:

Focus on simplifying local deployment

• Advantages: LobeHub emphasizes simplifying the deployment and usage process of local large language models, providing an easy-to-operate graphical user interface (GUI) for developers and non-technical users. This makes LobeHub especially suitable for users who do not want to rely on cloud services and need to control data and models locally.

• Comparison: Although frameworks like Hugging Face and DeepSpeed are powerful, most require developers to have a strong technical background, and they focus more on model fine-tuning and training processes, offering less support for local deployment.

User-friendly graphical user interface (GUI)

• Advantages: LobeHub provides an intuitive user interface, allowing non-technical personnel to easily run and manage models through a visual operation interface. This makes it more widely applicable and lowers the barrier to using large language models.

• Comparison: Frameworks like Hugging Face Transformers and GPT-NeoX mainly rely on command lines and APIs. Although powerful, they require certain programming and configuration skills. LobeHub, on the other hand, attracts users who do not want to dive deep into code.

Plugins and modular design

• Advantages: LobeHub supports plugin-based and modular expansion, which means users can easily add or remove features according to their needs. Its flexible design allows for easier integration of custom models and tools.

• Comparison: LangChain provides strong capabilities for integrating external tools and data, but it focuses more on complex workflows and multi-step reasoning. LobeHub is more suitable for simple model interaction and expansion.

Local operation, data privacy

• Advantages: LobeHub allows users to deploy and run large language models in local environments, ensuring complete control over data and privacy protection. For application scenarios where sensitive data is not suitable for uploading to the cloud, LobeHub is an ideal choice.

• Comparison: Frameworks like Hugging Face and OpenAI usually rely on cloud services, whereas LobeHub is suitable for users who need to process data locally, especially in enterprise or privacy-strict scenarios.

Simplifying model fine-tuning

• Advantages: LobeHub allows users to perform simple fine-tuning and customization on existing large language models, making the models more suitable for specific business scenarios. The fine-tuning process is relatively simple in LobeHub, making it suitable for users without a deep learning background.

• Comparison: DeepSpeed and GPT-NeoX also support large-scale model training and fine-tuning, but these frameworks are mainly geared towards users with high computing resources and deep learning knowledge. LobeHub focuses on reducing the complexity of fine-tuning, attracting a broader user base.

Support for multiple interaction modes

• Advantages: LobeHub not only provides a Web interface but also supports command-line interfaces (CLI) and API calls, flexibly adapting to different development scenarios and user needs. Whether they are technical personnel or ordinary users, they can interact with large language models in a way that suits them.

• Comparison: Although frameworks like Hugging Face and LangChain support multiple integration methods, their interaction methods mainly rely on programming interfaces, with less GUI support.

Performance Optimization

• Advantages: LobeHub is optimized for local running environments, supporting GPU acceleration and intelligently adjusting model execution based on system resources to ensure efficient inference, making it suitable for resource-constrained scenarios.

• Comparison: Frameworks like DeepSpeed excel in distributed computing and large-scale model training, but they have a certain dependency on high-performance hardware resources. LobeHub, on the other hand, is more suitable for individual users or small teams to achieve relatively efficient model inference on local devices.

Community-Driven and Open-Source Extension

• Advantages: LobeHub is an open-source project supported by the open-source community, where developers can share plugins, extensions, and solutions, as well as perform customized development. The active community provides strong technical support and resources.

• Comparison: Hugging Face also has an active community and a massive model library, but it focuses more on the cloud ecosystem. LobeHub, however, focuses on localized solutions and offers the convenience of plugin extensions.

The biggest advantages of LobeHub lie in its ”ease of use, data privacy, local deployment, graphical user interface,和and extensibility”, making it particularly suitable for users who want to run and manage large language models locally but do not want to spend a lot of effort configuring and maintaining them. Compared to more specialized and technology-oriented frameworks like Hugging Face, DeepSpeed, and LangChain, LobeHub is more suitable for individual users and small-to-medium enterprises who do not have deep learning knowledge but want to quickly use large models.

Therefore, I chose LobeHub as my open-source large language model UI framework, and the protagonist of this article, ”LobeChat”, is a specific application developed using the LobeHub framework: focusing on implementing dialogue systems based on large language models (official website introduction:https://lobehub.com/zh/docs/usage/start). Through LobeChat, users can directly interact with language model providers supported by LobeChat via APIs, which is similar to using a local ChatGPT client (except that ChatGPT is already bound to OpenAI's API).

Prerequisites

LobeChat Server-Side Database Version and Local Deployment Version

LobeChat is divided into two types: the server-side database version and the local deployment version. The server-side database version is a database-based chatbot server that can centrally store and manage conversation history, user data, and configuration files; while the local deployment version is actually just a simple Docker container that does not require a database, with all data content stored locally on the client accessing it.

Compared to the local deployment version, the server-side database version is more powerful and particularly suitable for larger-scale application scenarios. The main differences between the two are as follows:

LobeChat Server-Side Database Version:

  1. Data Storage and Management:

• Relies on databases (such as PostgreSQL, MySQL, etc.) to store conversation history, user information, logs, and configurations.
• Supports multi-user and multi-tenant management, suitable for enterprises or developer teams.
• Provides persistent data storage and advanced query functions, suitable for analysis and statistics.

  1. Object Storage Support:

• Requires S3-compatible object storage (such as MinIO or AWS S3) to manage uploaded files, model configurations, and static resources.
• Suitable for scenarios requiring large amounts of storage space, such as file sharing, model storage, etc.

  1. Scalability and Maintainability:

• The database version can be hybrid-deployed with cloud services and local servers, supporting larger-scale application scenarios.
• Easy to back up, restore, and migrate data, suitable for systems that require long-term operation and maintenance.

  1. Applicable Scenarios:

• Medium to large enterprises, SaaS application development.
• Projects requiring complex authentication, permission management, and persistent data storage.

LobeChat Local Deployment Version:

  1. Lightweight:

• Does not rely on external databases or object storage; data is typically stored in the local file system.
• Suitable for small projects or personal use, without involving multi-tenancy or complex user management.

  1. Simple Deployment:

• More lightweight and easy to install, requiring no complex database configuration or object storage.
• Faster deployment, suitable for short-term projects or experimental applications.

  1. Weaker Scalability:

• Due to the lack of database support, it is difficult to manage a large number of users, complex data, or perform data backup and analysis.
• Suitable for applications with smaller scales and less data.

Simply put, if there is no need for cross-device access (such as accessing from a mobile phone and syncing content with a computer), the LobeChat local deployment version is theoretically sufficient. However, if you want to use it across devices and still retain chat context, or if multiple users are using it together, you have no choice but to choose the server-side database version.

In the spirit of ”charge forward when there are difficulties, and create difficulties to charge forward even when there are none,” I naturally chose the server-side database version.

Introduction to Server-Side Database Version Components

PostgreSQL Database

PostgreSQL is a powerful open-source relational database management system featuring high extensibility and standard SQL support. It provides rich data types, concurrency processing, data integrity, security, and programmability, making it suitable for complex applications and large-scale data management.

In the deployment of the LobeChat server-side database version in this article, because file chat / knowledge base chat capabilities are supported, the PGVector plugin needs to be installed for the PostgreSQL database (this plugin provides vector search capabilities for Postgres and is one of the key components for LobeChat to implement RAG). Additionally, besides LobeChat itself, Logto, which is related to user authentication, also needs to use this database.

MinIO COS (Object Storage)

MinIO is a high-performance object storage system that is fully open-source and compatible with the Amazon S3 API. It is designed to simplify large-scale data storage and management in private, hybrid, and edge cloud environments, and most importantly, it supports self-hosted deployment.

Since the LobeChat server-side database version requires S3 storage to support multimodal AI conversations (users may upload files, images, documents, etc., during the chat), a usable S3-compatible storage is needed. The most convenient way is to self-host one using MinIO (I use Cloudflare R2 as my image hosting service and don't want to use up the precious 10GB free space~). Of course, any other S3-compatible object storage will work, so feel free to use whichever you prefer.

Logto

Logto is an open-source Identity and Access Management (IAM) platform designed to help developers easily integrate and manage user authentication, authorization, and Single Sign-On (SSO). It supports multiple authentication methods, such as standard protocols like OAuth 2.0 and OIDC (OpenID Connect), simplifying the process for developers to add user authentication to their applications.

LobeChat recommends using NextAuth: a flexible and powerful authentication library that supports various authentication methods, including OAuth, email login, credential login, etc. It can support multiple IdPs (Identity Providers, such as Google, GitHub, Email, etc., as well as custom solutions like Logto). In this article, we will adopt the self-hosted deployment method of Logto (actually, Logto also has a SaaS-based online service, but I didn't bother with it because there seemed to be too much information to fill out; there seems to be a free version suitable for individuals as well, so you can try it if you are interested).

Note: You can also use other authentication methods such as Auth0, Azure AD, Authentik, Zitadel, etc.

Deploy LobeChat

Preparation

Prepare 5 domain names:

  • lobe.tangwudi.com is used to access LobeChat
  • lobe-s3-ui.tangwudi.com and lobe-s3-api.tangwudi.com are used to access the WebUI and API calls of the self-hosted MinIO object storage, respectively.
  • lobe-auth-ui.tangwudi.com and lobe-auth-api.tangwudi.com are used to access the WebUI and API calls of Logto, respectively.

Note: Please determine the domain names according to your actual situation.

Create and enter the working directory

mkdir -p /docker/lebohub
cd /docker/lebohub

Note: Please modify the path according to your actual environment.

Configuration file comments

The official docker-compose.yml configuration file has many options, and there is also a dedicated environment variable file ”.env”. To make it easier for those who are not very familiar with it to understand, I have integrated all the parameters of the ”.env” file into docker-compose.yml and added comments. The commented version can be used directly (just replace the relevant parameters according to your actual environment).
docker-compose.yml:

services:
  # 部署postgres数据库
  postgresql:
    image: pgvector/pgvector:pg16 # 镜像地址
    container_name: lobe-postgres # 容器名称,logto和lobechat都需要用容器名称调用数据库
    ports:
      - '5432:5432' # 映射宿主机端口(左)到容器内部的相同端口,宿主机端口可按需修改。另,除了"ports",如果是vps部署且采用公网地址回源,可以使用"expose"的方式进行替代。
    volumes:
      - './data:/var/lib/postgresql/data' # 定义宿主机的挂载目录(:左)
    environment:
      - 'POSTGRES_DB=lobe' 
      - 'POSTGRES_PASSWORD=password' # 可按需修改,这两项需要在下面的lobe中引用
    healthcheck: 
      test: ['CMD-SHELL', 'pg_isready -U postgres'] #数据库健康检查
      interval: 5s
      timeout: 5s
      retries: 5
    restart: always # 容器保持开启

  # 部署minio,这一部分并不是必须的,如果采用其他S3兼容的对象存储或者有现成的minio,就只需要在最后部署lobechat时在参数中进行设置
  minio:
    image: minio/minio # 镜像地址
    container_name: lobe-minio # 容器名称
    ports:
      - '9000:9000' 
      - '9001:9001' # 映射宿主机端口(左)到容器内部的相同端口,宿主机端口可按需修改
    volumes:
      - './s3_data:/etc/minio/data' # 定义宿主机的挂载目录(:左)
    environment:
      - 'MINIO_ROOT_USER=root' # minio的root用户名,可按需修改
      - 'MINIO_ROOT_PASSWORD=password' # minio root用户密码,可按需修改
      - 'MINIO_DOMAIN=lobe-s3-api.tangwudi.com'  # 定义minio的api调用地址
      - 'MINIO_API_CORS_ALLOW_ORIGIN=https://lobe.tangwudi.com' # 为lobechat的地址配置CORS的访问权限
    restart: always  # 容器保持开启
    command: >
      server /etc/minio/data --address ":9000" --console-address ":9001"

 # 部署logto,这一部分不是必须的,如果采用其他的身份验证方式,就只需要在最后部署lobechat时在参数中进行设置
  logto:
    image: svhd/logto # 镜像地址
    container_name: lobe-logto # 容器名称
    ports:
      - '3001:3001' # logto api
      - '3002:3002' # logto ui
    depends_on:  # 指定logto容器启动的依赖关系,这里表示需要service postgresql先启动
      postgresql:
        condition: service_healthy # logto容器启动的前置条件是postgresql容器通过健康检查,相当于在postgresql先启动之外又加了一个条件
    environment:
      - 'TRUST_PROXY_HEADER=1'
      - 'DB_URL=postgresql://postgres:password@lobe-postgres:5432/logto' # 设置数据库地址URL,注意这里的5432是容器内部端口
      - 'ENDPOINT=https://lobe-auth-api.tangwudi.com' # 设置logto api的地址
      - 'ADMIN_ENDPOINT=https://lobe-auth-ui.tangwudi.com' # 设置logto ui的地址
    entrypoint: ['sh', '-c', 'npm run cli db seed -- --swe && npm start'] # 为logto初始化数据库

  # 部署lobechat
  lobe:
    image: lobehub/lobe-chat-database # 镜像地址
    container_name: lobe-database # 容器名称
    ports:
      - '3210:3210' # 映射宿主机端口(左)到容器内部的相同端口,宿主机端口可按需修改
    environment:
    # lobechat链接数据库的具体地址
      - 'DATABASE_URL=postgresql://postgres:password@lobe-postgres:5432/lobe'
      - 'KEY_VAULTS_SECRET=Kix2wcUONd4CX51E/ZPAd36BqM4wzJgKjPtz2sGztqQ=' # 数据库密钥
      - 'APP_URL=https://lobe.tangwudi.com/' # 必填LobeChat 域名,用于tRPC调用,请保证此域名在你的 NextAuth 鉴权服务提供商、S3 服务商的 CORS 白名单中
      - 'NEXT_AUTH_SSO_PROVIDERS=logto' # 必填,指定鉴权服务提供商,这里以 Logto 为例
      - 'NEXT_AUTH_SECRET=Kix2wcUONd4CX51E/ZPAd36BqM4wzJgKjPtz2sGztqQ=' # 必填,用于NextAuth的密钥,可以使用openssl rand -base64 32 生成
      - 'NEXTAUTH_URL=https://lobe.tangwudi.com/api/auth' # 必填,NextAuth 的 URL,用于 NextAuth 的回调
      - 'LOGTO_ISSUER=https://lobe-auth-api.tangwudi.com/oidc' # 指定Logto身份验证提供商(Identity Provider, IdP)的"授权服务器地址"
      - 'LOGTO_CLIENT_ID=xxxxxxxxx' # 需要登录logto创建应用后获取
      - 'LOGTO_CLIENT_SECRET=1IuPFNm08E5pdEk1Fd7OQWbmw05GM53n' # 同上
      - 'S3_ENDPOINT=https://lobe-s3-api.tangwudi.com' # 必填,S3的Endpoint,用于服务端/客户端连接到 S3 API
      - 'S3_BUCKET=lobe' # 必填,S3的Bucket,直到在MinIO UI中手动创建之前都是无效的
      - 'S3_PUBLIC_DOMAIN=https://lobe-s3-api.tangwudi.com' # 必填,S3的Public Domain,用于客户端通过公开连接访问非结构化数据
      - 'S3_ACCESS_KEY_ID=xxxxxxxxxx' # 需要登录minio后手动创建
      - 'S3_SECRET_ACCESS_KEY=xxxxxxxxxxxx' # 同上
      - 'S3_ENABLE_PATH_STYLE=1' # 对于主流 S3 Cloud 服务商,一般填 0 即可;对于自部署的 MinIO,请填 1
    depends_on: # 指定lobe启动的依赖关系,需要在其他3个service启动之后再启动
      - postgresql
      - minio
      - logto
    restart: always # 容器保持开启

volumes:
  data:
    driver: local
  s3_data:
    driver: local

Note 1: Some parameters in the logto or S3 sections of the file, if self-hosted (logto and minio), can only be obtained after setting them up in the corresponding UI once the applications are pulled up. Therefore, the LobeChat server database version cannot be fully configured by pulling up all applications with a single ”docker-compose up -d”. You need to pull up all applications for the first time, configure some of them to obtain and complete these parameters, and then use the ”docker-compose down && docker-compose up -d” command again for formal deployment. Thus, you need to run the ”docker-compose up -d” command at least twice.

Note 2: Before officially starting the deployment, you need to complete 5 domain-related preparations, as follows:

  • Complete the resolution of the 5 domains
  • Configure the reverse proxy according to the corresponding ports of each component on the host machine in the docker-compose.yml configuration file to ensure that the following URLs are available:
https://lobe.tangwudi.com --> http://lobe-database:3210
https://lobe-s3-ui.tangwudi.com/ --> http://lobe-minio:9001
https://lobe-s3-api.tangwudi.com --> http://lobe-minio:9000
https://lobe-auth-ui.tangwudi.com/.tangwudi.com --> http://lobe-logto:3002
https://lobe-auth-api.tangwudi.com --> http://lobe-logto:3001

Note 3: The reverse proxy settings need to be configured according to the reverse proxy software you usually use. If you are using NPM or aaPanel (Baota) to configure the reverse proxy, you can refer to my previous article:Docker Series: Building Your Own Reverse Proxy Based on NPM Using DockerandLinux Panel Series: Configuring Reverse Proxy and Publishing Using Non-443 Ports。

Note 4: If you are using Cloudflare Tunnel to build the site, it is much more convenient. You can configure it directly in the ”Public hostnames” section of the corresponding tunnel. For detailed configuration steps, please refer to the article:Home Data Center Series: Using Tunnel Technology to Enable Home Broadband Without Public IP to Leverage Cloudflare for Free to Achieve Rapid Website Setup (Recommended)However, using Cloudflare Tunnel also has potential risks, as you cannot configure Cloudflare's behavior when fetching from the origin (unlike Nginx's reverse proxy, which allows many options). This might cause Logto to malfunction (maybe another Nginx is needed as a reverse proxy in this case? Never mind, too much hassle).

Official Deployment

Pull up all applications

cd /docker/lobehub
vim docker-compose.yml # 将上节中的配置文件内容粘贴进来并保存
docker-compose up -d # 拉起所有应用

Note: Please delete ”#” and the subsequent comment content in the above text yourself.

Normally, all container statuses should be normal:

image.png

Set up Logto and MinIO

Logto

Use linkhttps://lobe-auth-ui.tangwudi.comLog in to Logto; you need to create an admin account for the first login:

image.png

image.png

You can set the language in the top right corner:
image.png

image.png

Create a Next.js application:
image.png

Note the content in the red box in the image below:
image.png

The code for the Redirect URIs section is as follows. Please replace the domain part with your actual LobeChat domain:

https://lobe.tangwudi.com/api/auth/callback/logto

Record the content of ”App ID” and ”App secrets” in the image below, which will need to be filled into the docker-compose.yml file later:

image.png

MinIO

Usehttps://lobe-s3-ui.tangwudi.com/Log in to MinIO:

image.png

Configure according to the content of the following image:
image.png

image.png

image.png

image.png

image.png

The access policy in the image above is as follows (assuming the bucket name is ”lobe”, please replace it if it is another name):

{
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": ["*"]
      },
      "Action": ["s3:GetBucketLocation"],
      "Resource": ["arn:aws:s3:::lobe"]
    },
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": ["*"]
      },
      "Action": ["s3:ListBucket"],
      "Resource": ["arn:aws:s3:::lobe"],
      "Condition": {
        "StringEquals": {
          "s3:prefix": ["files/*"]
        }
      }
    },
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": ["*"]
      },
      "Action": ["s3:PutObject", "s3:DeleteObject", "s3:GetObject"],
      "Resource": ["arn:aws:s3:::lobe/files/**"]
    }
  ],
  "Version": "2012-10-17"
}

Next, create the MinIO API key:

image.png

Just click ”Create” to create it:
image.png

Record the content of the Access Key and Secret Key in the image below during actual operation:
image.png

Redeploy

Delete the previous Stacks. After filling in the S3 and Logto related content obtained earlier in the lobechat-database section of docker-compose.yml, use the complete docker-compose.yml file to pull up all applications again:

docker-compose down
docker-compose up -d

Use the following command to view the LobeChat status:

docker logs -f lobe-database

The following display indicates a normal startup:

image.png


For deployment in more scenarios, you can directly refer to the official documentation:https://lobehub.com/zh/docs/self-hosting/start, although there are many pitfalls, it is still quite detailed and can be used as a reference.


Additional Content 1: Using GitHub instead of Logto

There are quite a few settings for Logto, and a reverse proxy is required during deployment. Improper configuration can lead to access issues (for example, failing to add the setting: ”proxy_set_header X-Forwarded-Proto https;” in the Nginx reverse proxy). For some friends who only use it for themselves, spending too much time and effort configuring Logto is not really worth it, so I am separately adding content on using GitHub for authentication (of course, provided you have a GitHub account~).

For detailed steps on setting up GitHub, please refer to the graphic tutorial below.

First, click the link to start adding the GitHub App:https://github.com/settings/apps/new

image.png

image.png

image.png

image.png

Create a client secret:
image.png

image.png

Remember the Client ID and Client Secret content in the red box in the image below, which need to be added to the ”GITHUB_CLIENT_ID” and ”GITHUB_CLIENT_SECRET” parameters in the lobechat-database section of docker-compose.yml:
image.png

Then, just like before, configure MinIO first to obtain the values of ”S3_ACCESS_KEY_ID” and ”S3_SECRET_ACCESS_KEY”, and complete them in the corresponding parameter section of lobechat-database in the docker-compose.yml file as well.

Finally, the complete content of docker-compose.yml is as follows:

services:
# 部署postgresql数据库
  postgresql:
    image: pgvector/pgvector:pg16 # 镜像地址
    container_name: lobe-postgres # 容器名称,logto和lobechat都需要用容器名称调用数据库
    expose:
      - '5432' # 映射宿主机端口(左)到容器内部的相同端口,宿主机端口可按需修改。另,除了"ports",如果是vps部署且采用公网地址回源,可以使用"expose"的方式进行替代。
    volumes:
      - './data:/var/lib/postgresql/data' # 定义宿主机的挂载目录(:左)
    environment:
      - 'POSTGRES_DB=lobe' 
      - 'POSTGRES_PASSWORD=password' # 可按需修改,这两项需要在下面的lobe中引用
    healthcheck: 
      test: ['CMD-SHELL', 'pg_isready -U postgres'] #数据库健康检查
      interval: 5s
      timeout: 5s
      retries: 5
    restart: always # 容器保持开启

  # 部署minio,这一部分并不是必须的,如果采用其他S3兼容的对象存储或者有现成的minio,就只需要在".env"文件中进行设置
  minio:
    image: minio/minio # 镜像地址
    container_name: lobe-minio # 容器名称
    ports:
      - '9000:9000' 
      - '9001:9001' # 映射宿主机端口(左)到容器内部的相同端口,宿主机端口可按需修改
    volumes:
      - './s3_data:/etc/minio/data' # 定义宿主机的挂载目录(:左)
    environment:
      - 'MINIO_ROOT_USER=root' # minio的root用户名,可按需修改
      - 'MINIO_ROOT_PASSWORD=password' # minio root用户密码,可按需修改
      - 'MINIO_DOMAIN=lobe-s3-api.tangwudi.com'
      - 'MINIO_API_CORS_ALLOW_ORIGIN=https://lobe.tangwudi.com' # 为lobechat的地址配置CORS的访问权限
    restart: always  # 容器保持开启
    command: >
      server /etc/minio/data --address ":9000" --console-address ":9001"

  # 部署lobechat服务端数据库版
  lobe:
    image: lobehub/lobe-chat-database # 镜像地址
    container_name: lobe-database # 容器名称
    ports:
      - '3210:3210' # 映射宿主机端口(左)到容器内部的相同端口,宿主机端口可按需修改
    environment:
      - 'DATABASE_URL=postgresql://postgres:password@lobe-postgres:5432/lobe'
      - 'KEY_VAULTS_SECRET=Kix2wcUONd4CX51E/ZPAd36BqM4wzJgKjPtz2sGztqQ='
      - 'APP_URL=https://lobe.tangwudi.com/' # 必填LobeChat 域名,用于tRPC调用,请保证此域名在你的 NextAuth 鉴权服务提供商、S3 服务商的 CORS 白名单中
      - 'NEXT_AUTH_SSO_PROVIDERS=github' # 必填,指定鉴权服务提供商,这里改为github
      - 'NEXT_AUTH_SECRET=Kix2wcUONd4CX51E/ZPAd36BqM4wzJgKjPtz2sGztqQ=' # 必填,用于NextAuth的密钥,可以使用openssl rand -base64 32 生成
      - 'NEXTAUTH_URL=https://lobe.tangwudi.com/api/auth' # 必填,NextAuth 的 URL,用于 NextAuth 的回调
      - 'GITHUB_CLIENT_ID=xxxx' # 前面获取的GITHUB_CLIENT_ID的内容
      - 'GITHUB_CLIENT_SECRET=xxxxx' # 前面获取的GITHUB_CLIENT_SECRET的内容
      - 'S3_ENDPOINT=https://lobe-s3-api.tangwudi.com' # 必填,S3 的 Endpoint,用于服务端/客户端连接到 S3 API
      - 'S3_BUCKET=lobe' # 必填,S3 的 Bucket,直到在MinIO UI中手动创建之前都是无效的
      - 'S3_PUBLIC_DOMAIN=https://lobe-s3-api.tangwudi.com' # 必填,S3 的 Public Domain,用于客户端通过公开连接访问非结构化数据
      - 'S3_ACCESS_KEY_ID=xxxxxxxxxx' 
      - 'S3_SECRET_ACCESS_KEY=xxxxxxxxxxxx'
      - 'S3_ENABLE_PATH_STYLE=1' # 对于主流 S3 Cloud 服务商,一般填 0 即可;对于自部署的 MinIO,请填 1
    depends_on: # 指定lobe启动的依赖关系,需要在其他3个service启动之后再启动
      - postgresql
      - minio
    restart: always # 容器保持开启

volumes:
  data:
    driver: local
  s3_data:
    driver: local

Note: You still need to run ”docker-compose up -d” twice. However, if you are directly using third-party object storage, such as Cloudflare R2, and also using a third-party authentication method like GitHub, you only need to run the ”docker-compose up -d” command once after filling in the relevant parameters.

Additional Content 2: Deployment via docker run

Originally, for projects with multiple interconnected containers like this, deploying via docker-compose is the most convenient. However, separate deployment also has its benefits, making it more convenient to maintain a specific container individually when needed, and also facilitating troubleshooting when deployment issues arise. Therefore, I will still provide the docker run format commands for each container for everyone's convenience when needed.

Create working directory:

mkdir -p /docker/lobehub
cd /docker/lobehub
mkdir -p postgres/data
mkdir s3_data

cd /docker/lobehub

docker network create public-net

mkdir -p postgres/data

docker run --name lobe-postgres -d --restart=always --net=public-net \
 -e POSTGRES_DB=lobe \
 -e POSTGRES_PASSWORD=password \
 -p 5432:5432 \
 -v /docker/lobehub/postgres/data:/var/lib/postgresql/data \
 pgvector/pgvector:pg16

Create docker network:

docker run --name lobe-logto -d --restart=always --net=public-net \
 -e POSTGRES_PASSWORD=password \
 -p 3001:3001 \
 -p 3002:3002 \
 -e TRUST_PROXY_HEADER=1 \
 -e DB_URL=postgresql://postgres:password@lobe-postgres:5432/logto \
 -e ENDPOINT=https://lobe-auth-api.tangwudi.com \
 -e ADMIN_ENDPOINT=https://lobe-auth-ui.tangwudi.com \
 --entrypoint sh \
 svhd/logto -c 'npm run cli db seed -- --swe && npm start'

minio:

docker run --name lobe-minio -d --restart=always --net=public-net \
  -p 9000:9000 \
  -p 9001:9001 \
  -v /docker/lobehub/s3_data:/etc/minio/data \
  -e MINIO_ROOT_USER=root \
  -e MINIO_ROOT_PASSWORD=password \
  -e MINIO_DOMAIN=lobe-s3-api.tangwudi.com \
  -e MINIO_API_CORS_ALLOW_ORIGIN=https://lobe.tangwudi.com \
  --restart always \
  minio/minio server /etc/minio/data --address ":9000" --console-address ":9001"

lobechat-database:

docker run --name lobe-database -d --restart=always --net=public-net \
  -p 3210:3210 \
  -e DATABASE_URL=postgresql://postgres:password@lobe-postgres:5432/lobe \
  -e KEY_VAULTS_SECRET=Kix2wcUONd4CX51E/ZPAd36BqM4wzJgKjPtz2sGztqQ= \
  -e APP_URL=https://lobe.tangwudi.com/ \
  -e NEXT_AUTH_SSO_PROVIDERS=logto \
  -e NEXT_AUTH_SECRET=Kix2wcUONd4CX51E/ZPAd36BqM4wzJgKjPtz2sGztqQ= \
  -e NEXTAUTH_URL=https://lobe.tangwudi.com/api/auth \
  -e LOGTO_ISSUER=https://lobe-auth-api.tangwudi.com/oidc \
  -e S3_ENDPOINT=https://lobe-s3-api.tangwudi.com \
  -e S3_BUCKET=lobe \
  -e S3_PUBLIC_DOMAIN=https://lobe-s3-api.tangwudi.com \
  -e S3_ENABLE_PATH_STYLE=1 \
  --env-file .env \
  lobehub/lobe-chat-database

By the way, here is the command for the locally deployed version of lobechat, which is basically enough for friends who don't want to mess around and only use it locally:

docker run --name lobe-chat  -d --restart=always \
  -p 3210:3210 \
  -e ACCESS_CODE=xxx \
  lobehub/lobe-chat

Other configurations can be set directly in the locally deployed version of lobechat.

LobeChat Basic Settings

Log in using the LobeChat domain name

Access URLhttps://lobe.tangwudi.comLog in to lobechat:

image.png

image.png

Then register and log in following the normal process:
image.png

If using GitHub for authentication, manual confirmation is required:
image.png

Note 1: If there is a WAF and hotlink protection or similar policies are deployed, you need to add ”github.com“ to the access whitelist.

Note 2: If using logto and minio, pay attention to the CORS-related settings for both.

Change display language

You can modify it by following these steps:

image.png

image.png

image.png

Configure language models

lobechat supports multiple language models:

image.png

image.png

image.png

Taking Azure OpenAI as an example:
image.png

image.png

Quick overview of other common content

System Assistant:

image.png

Session:
image.png

file:
image.png

Discover:
image.png

The above is just an introduction to the most basic interface of Lobechat. In fact, there are still many details inside. I have just installed it myself and haven't officially used it yet, so I don't know the details. After I use it for a while, I will see if I need to write a dedicated article on how to use Lobechat.

Summary

There were many pitfalls in this deployment, especially with logto. If you are unlucky, you will encounter a bunch of inexplicable problems (such as encountering an internal error right after logging in, spinning endlessly and failing to create when creating a Next.js application, etc. Anyway, all kinds of bugs are reported on GitHub~). I feel like most of my time was wasted on this (because the relevant links must be https, so it also involves reverse proxy configuration). I also encountered a strange problem where logto would report an error and exit as soon as the lobechat-database container started. In the end, after a lot of tossing, I don't even know how it got fixed.

The authentication of the lobechat server database version is essentially throwing the login request to a third-party authentication service for verification. After passing the verification, the third-party authentication service throws the access request back to lobechat. If configured improperly, either it cannot be sent over (CORS policy is not configured properly), or it cannot be sent back (intercepted by hotlink protection policy). It is nothing more than these two situations. Please pay attention to this when troubleshooting problems.


For example: I failed when using GitHub for authentication. Later, I found out it was because of the hotlink protection policy I set on Cloudflare WAF, which directly caused GitHub to be intercepted by the WAF during the callback:

image.png

After that, just add requests whose referer contains the ”github.com” field to the hotlink protection whitelist in the hotlink protection settings.


Finally, I suggest simplifying the components that need to be deployed as much as possible. For example, use a third-party S3 object storage (such as Cloudflare R2, Amazon S3), and use the third-party IdP that suits you best for authentication (such as GitHub). In this way, the only components that need to be deployed locally are the Postgres database and lobechat, and the probability of problems will be greatly reduced.

P.S.: A friend in the comment section posted a flowchart of the article drawn by AI, which is very interesting. I'll "steal" the image and post it:

image.png

View Related Categories · 3 Matches
📌 Content Structure Prompt:
This content is part of the following knowledge map, where you can view the complete content path: AI Learning Map。
📎 Related Articles
Share this article
The blog content is original, please indicate the source when reposting! The RSS address of the blog is:https://blog.tangwudi.com/feed, welcome to subscribe; if needed, you can join theTelegram Groupto discuss questions together.

Comments

  1. jm
    Macintosh Edge 133.0.0.0
    Edited
    2 years ago
    2025-2-25 16:36:11

    Deploying minio via command line first and then using yml makes things much clearer, no need to deploy yml twice.

    • Owner
      jm
      iPhone Chrome 133.0.6943.120
      2 years ago
      2025-2-25 17:11:06

      Isn't there a copy button in the top right corner of the code block?

  2. aling
    iPhone Chrome 124.0.6367.111
    2 years ago
    2024-11-03 17:28:31

    The blogger's website design is right up my alley. May I ask what tech stack or template you used?

  3. aling
    iPhone Chrome 124.0.6367.111
    2 years ago
    2024-11-03 17:27:26

    An enlightening article after being shut down for 48 hours due to issues with self-hosting lobehub

    • Owner
      aling
      Macintosh Chrome 130.0.0.0
      2 years ago
      2024-11-03 20:24:51

      Actually, deploying the lobechat server database version is not complicated, it's just that there are too many options. If you choose the most suitable options from the start, it's actually very simple. The official deployment tutorial covers too many scenarios, which easily confuses people.

  4. Ergou
    Windows Edge 129.0.0.0
    2 years ago
    2024-9-23 17:55:05



    Show Image



    Another diagram

    • Owner
      Ergou
      Macintosh Edge 128.0.0.0
      2 years ago
      2024-9-23 19:58:45

      Great, great, this is also on the list of practical technologies I plan to study later.

  5. Ergou
    Windows Edge 129.0.0.0
    2 years ago
    2024-9-23 17:51:59



    Show Image



    AI drew a diagram of your article, the effect is not bad

    • Owner
      Ergou
      Macintosh Edge 128.0.0.0
      2 years ago
      2024-9-23 19:57:32

      This feature is quite nice.

    • Owner
      Ergou
      Macintosh Edge 128.0.0.0
      2 years ago
      2024-9-23 20:19:16

      I'll "steal" your image and put it in the article.

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗ
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
Kaomoji
Emoji
Little Dinosaur
Flower!
Previous
Next
       

👋 Welcome to “Wudi's Personal Blog”

Here, long-term exploration is mainly carried out around the following directions:

🧱 Personal Digital Infrastructure and Blog System Construction
☁️ Cloudflare and Network Architecture Practice
🧠 AI and Knowledge System Exploration
🛡️ Network Security and Access Optimization
🎵 Music and Sound Cognition
👁️ Cognitive Perspectives and Worldviews