教程用 Docker Compose 部署 Dify 及 Nginx、PostgreSQL、Redis、Weaviate,并通过 Certbot 配置 HTTPS。随后连接模型供应商,搭建基于 Chatflow 的客服机器人。
Dify 是一个开源 LLM 应用开发平台,提供可视化工作流设计、RAG 流水线、Agent、模型管理和可观测性,并支持数百种专有及开源模型。本指南将部署 Dify 自带的 Docker Compose 技术栈(Nginx、PostgreSQL、Redis、Weaviate),通过 Certbot 配置 Let's Encrypt TLS、连接模型提供商,并构建一个基于 Chatflow 的客服聊天机器人。
前置条件:一台 Linux 服务器(最低配置为 2 vCPU / 4GB RAM)、Docker + Docker Compose、一个已配置 A 记录的域名(例如 dify.example.com),以及模型提供商(OpenAI、Anthropic、Cohere 等)的 API key。
$ curl -sL https://github.com/langgenius/dify/archive/refs/tags/1.14.1.tar.gz | tar -xz
$ mv dify-1.14.1 ~/dify
$ cd ~/dify/docker
$ cp .env.example .env
$ sed -i "s|^SECRET_KEY=.*|SECRET_KEY=$(openssl rand -base64 42)|" .env
根据你的域名编辑 .env。默认文件中没有 CERTBOT_DOMAIN/CERTBOT_EMAIL,需要手动添加:
$ nano .env
NGINX_SERVER_NAME=dify.example.com
NGINX_SSL_CERT_FILENAME=fullchain.pem
NGINX_SSL_CERT_KEY_FILENAME=privkey.pem
NGINX_ENABLE_CERTBOT_CHALLENGE=true
CONSOLE_API_URL=https://dify.example.com
CONSOLE_WEB_URL=https://dify.example.com
SERVICE_API_URL=https://dify.example.com
APP_API_URL=https://dify.example.com
APP_WEB_URL=https://dify.example.com
CERTBOT_DOMAIN=dify.example.com
CERTBOT_EMAIL=admin@example.com
Dify 自带一个超过 1,200 行的 Compose 文件,其中包含 PostgreSQL、Redis、Weaviate 向量存储、Nginx 和应用服务。部署分为两个阶段:先通过 HTTP 启动服务,然后申请证书并切换到 HTTPS。
$ docker compose up -d
$ docker compose ps -a
所有服务都应该显示 Up;对于定义了健康检查的服务(db_postgres、redis、sandbox),还应显示 healthy。
$ docker compose --profile certbot up -d certbot
$ docker compose exec certbot /bin/sh /update-cert.sh
Certbot 会执行 HTTP-01 challenge,并将证书写入 volumes/certbot/conf/live/<domain>/。
$ sed -i "s|^NGINX_HTTPS_ENABLED=.*|NGINX_HTTPS_ENABLED=true|" .env
$ docker compose --profile certbot up -d --no-deps --force-recreate nginx
在 https://dify.example.com/install 创建管理员账户:填写 email、username 和 password,然后点击 Set up。
连接模型提供商:点击 profile avatar → Settings → Model Provider → 找到你的模型提供商(OpenAI、Anthropic、DeepSeek 等)→ Install(Dify 会按需从其 marketplace 拉取对应 plugin)→ 粘贴 API key → Save。确认该提供商已经出现在已配置的提供商列表中,并且至少有一个可用的 chat model。
依次进入 Studio → Create from Blank → Chatflow。将其命名为 Support Assistant,设置 icon 和 description,然后点击 Create。创建后会得到预先连接好的 Start → LLM → Answer 节点。
配置 LLM 节点:
选择你的 chat model(例如 gpt-4o、claude-sonnet-5)。
You are a customer support agent for a SaaS product. Answer questions about billing, installation, and integrations in a clear, concise tone. Refer the user to the documentation when a question falls outside your knowledge.
启用 MEMORY,并将 WINDOW SIZE 设置为 10,以保留对话上下文。
点击 Publish → Publish Update。
测试应用:打开 Preview,发送类似下面的消息:The platform charged the subscription twice this month. Can you help with a refund? ——确认回复连贯并且紧扣问题。
独立运行:点击 Publish 下拉菜单 → Run App,打开专用的聊天界面。
至此,Dify 已通过 TLS 正常运行,并且拥有一个由你的模型提供商驱动、能够感知对话记忆的聊天机器人。接下来可以:
如需查看完整指南,请访问 Vultr Docs 上的原始文章。
对于后续操作,你可以考虑屏蔽此人和/或举报滥用行为。