复制成功
请遵守本站许可
REPORT
Chapter_Post // Field_Report

Post_Ref: RL-DIFY应用发布

2026.04.08

Dify应用发布和部署

Echo HaoRan
Echo HaoRan
ANALYSIS
  • Docker
  • HTTP
  • Kubernetes
  • PostgreSQL
  • Posts
  • Python

Dify 应用发布和部署#

概述#

Dify 提供多种发布和部署方式,让你可以将创建的 AI 应用快速推向用户。本文将详细介绍如何将应用发布为 Web 站点、API 工具,以及如何进行私有化部署。


发布方式概览#

发布方式复杂度适用场景特点
Web 应用快速分享、用户体验几分钟即可发布
API 工具集成到现有系统灵活的 API 接口
MCP 服务器Claude Desktop 集成新兴标准协议
私有化部署企业级应用数据隐私、完全控制

发布为 Web 应用#

快速发布#

步骤

  1. 进入应用详情页
  2. 点击 发布
  3. 选择 发布更新
  4. 等待发布完成

访问地址

PRTCL // PLAINTEXT
https://cloud.dify.ai/chatbot/xxx

Web 应用设置#

基础设置

PRTCL // YAML
Web 应用配置:
enabled: true
site_name: "我的应用"
site_title: "AI 助手"
description: "这是一个智能 AI 助手"
icon: "https://example.com/icon.png"

主题配置

PRTCL // YAML
主题配置:
primary_color: "#007AFF"
background_color: "#F5F5F5"
text_color: "#333333"
font_family: "Inter, sans-serif"
border_radius: 8

高级设置

PRTCL // YAML
高级配置:
custom_domain: "app.example.com"
ssl_enabled: true
analytics:
enabled: true
provider: "google_analytics"
tracking_id: "UA-XXXXXXXXX"

功能配置#

对话设置

PRTCL // YAML
对话配置:
opening_statement: "您好!有什么可以帮您的吗?"
suggested_questions:
- "如何使用产品?"
- "产品有哪些功能?"
- "常见问题有哪些?"
voice_input:
enabled: true
language: "zh-CN"
voice_output:
enabled: true
voice: "female"

显示设置

PRTCL // YAML
显示配置:
show_branding: false # 隐藏 Dify 品牌信息
show_footer: true
show_header: true
show_share_button: true

访问控制#

公开访问

PRTCL // YAML
访问控制:
type: "public"
authentication: false

私有访问

PRTCL // YAML
访问控制:
type: "private"
authentication: true
allowed_users:
- "user@example.com"
- "user2@example.com"

密码保护

PRTCL // YAML
访问控制:
type: "password"
password: "your_password"

API 集成#

生成 API 凭据#

步骤

  1. 进入应用详情页
  2. 点击 API Access
  3. 点击 创建凭据
  4. 输入凭据名称
  5. 点击 创建
  6. 保存 API Key

API 文档#

Dify 会自动生成完整的 API 文档,包括:

  • 端点 URL
  • 请求方法
  • 请求参数
  • 响应格式
  • 示例代码

查看文档

  1. 进入 API Access 页面
  2. 点击 查看文档
  3. 查看详细的 API 说明

文本生成 API#

端点POST https://api.dify.ai/v1/completion-messages

请求示例

PRTCL // BASH
Terminal window
curl --location --request POST 'https://api.dify.ai/v1/completion-messages' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {
"text": "Hello, how are you?"
},
"response_mode": "streaming",
"user": "abc-123"
}'

Python 示例

PRTCL // PYTHON
import requests
import json
url = "https://api.dify.ai/v1/completion-messages"
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
}
data = {
"inputs": {
"text": "Hello, how are you?"
},
"response_mode": "streaming",
"user": "abc-123"
}
response = requests.post(url, headers=headers, json=data)
print(response.text)

对话 API#

端点POST https://api.dify.ai/v1/chat-messages

请求示例

PRTCL // BASH
Terminal window
curl --location --request POST 'https://api.dify.ai/v1/chat-messages' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {},
"query": "Hello",
"response_mode": "streaming",
"conversation_id": "",
"user": "abc-123"
}'

Python 示例

PRTCL // PYTHON
import requests
import json
url = 'https://api.dify.ai/v1/chat-messages'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
}
data = {
"inputs": {},
"query": "Hello",
"response_mode": "streaming",
"conversation_id": "",
"user": "abc-123"
}
response = requests.post(url, headers=headers, json=data)
print(response.text)

API 安全#

最佳实践

PRTCL // YAML
安全配置:
credentials:
development:
api_key: "${DIFY_DEV_API_KEY}"
testing:
api_key: "${DIFY_TEST_API_KEY}"
production:
api_key: "${DIFY_PROD_API_KEY}"
security:
rate_limit: 100 # 每小时 100 次
ip_whitelist: true
allowed_ips:
- "192.168.1.0/24"
- "10.0.0.0/8"

发布为 MCP 服务器#

什么是 MCP#

MCP(Model Context Protocol)是一种让 AI 工具之间相互通信的标准协议。通过 MCP,你可以将 Dify 应用集成到 Claude Desktop 等 AI 工具中。

发布步骤#

步骤

  1. 进入应用详情页
  2. 点击 发布
  3. 选择 发布为 MCP 服务器
  4. 配置 MCP 参数
  5. 点击 发布

MCP 配置#

基础配置

PRTCL // YAML
MCP 配置:
enabled: true
server_name: "my-dify-app"
description: "我的 Dify 应用"
version: "1.0.0"

工具配置

PRTCL // YAML
工具配置:
tools:
- name: "generate_content"
description: "生成内容"
input_schema:
type: "object"
properties:
topic:
type: "string"
description: "主题"
style:
type: "string"
description: "风格"
required:
- "topic"

使用 MCP#

在 Claude Desktop 中使用

  1. 打开 Claude Desktop
  2. 进入设置
  3. 添加 MCP 服务器
  4. 输入 Dify 提供的 MCP URL
  5. 开始使用

私有化部署#

部署方式#

Dify 支持多种私有化部署方式:

方式复杂度适用场景
Docker小规模部署
Docker Compose中等规模部署
Kubernetes大规模部署
源码部署自定义部署

Docker 部署#

步骤

PRTCL // BASH
Terminal window
# 拉取镜像
docker pull langgenius/dify:latest
# 运行容器
docker run -d \
--name dify \
-p 80:80 \
-e DATABASE_URL="postgresql://user:password@host:5432/dify" \
-e REDIS_URL="redis://host:6379" \
langgenius/dify:latest

Docker Compose 部署#

docker-compose.yml

PRTCL // YAML
version: '3.8'
services:
dify-web:
image: langgenius/dify-web:latest
ports:
- "3000:3000"
depends_on:
- dify-api
environment:
- API_URL=http://dify-api:5001
dify-api:
image: langgenius/dify-api:latest
ports:
- "5001:5001"
depends_on:
- db
- redis
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/dify
- REDIS_URL=redis://redis:6379/0
db:
image: postgres:15-alpine
volumes:
- ./data/postgres:/var/lib/postgresql/data
environment:
- POSTGRES_DB=dify
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
redis:
image: redis:7-alpine
volumes:
- ./data/redis:/data

启动服务

PRTCL // BASH
Terminal window
docker-compose up -d

Kubernetes 部署#

deployment.yaml

PRTCL // YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: dify-api
spec:
replicas: 3
selector:
matchLabels:
app: dify-api
template:
metadata:
labels:
app: dify-api
spec:
containers:
- name: dify-api
image: langgenius/dify-api:latest
ports:
- containerPort: 5001
env:
- name: DATABASE_URL
value: "postgresql://postgres:postgres@db:5432/dify"
- name: REDIS_URL
value: "redis://redis:6379/0"

启动服务

PRTCL // BASH
Terminal window
kubectl apply -f deployment.yaml

监控和维护#

监控指标#

关键指标

PRTCL // YAML
监控指标:
- name: "API 响应时间"
target: "< 1s"
- name: "成功率"
target: "> 99%"
- name: "并发用户数"
target: "< 1000"
- name: "错误率"
target: "< 1%"

日志管理#

日志配置

PRTCL // YAML
日志配置:
level: "info" # debug, info, warn, error
format: "json"
outputs:
- type: "console"
enabled: true
- type: "file"
enabled: true
path: "/var/log/dify"
max_size: "100M"
max_files: 10

备份策略#

备份配置

PRTCL // YAML
备份配置:
enabled: true
schedule: "0 2 * * *" # 每天 2:00
retention:
daily: 7
weekly: 4
monthly: 12
storage:
type: "s3"
bucket: "dify-backups"
region: "us-east-1"

安全配置#

认证和授权#

认证配置

PRTCL // YAML
认证配置:
enabled: true
method: "jwt" # jwt, oauth2, saml
jwt:
secret: "${JWT_SECRET}"
expiration: "24h"
refresh_expiration: "7d"

授权配置

PRTCL // YAML
授权配置:
enabled: true
strategy: "rbac" # rbac, abac
roles:
- name: "admin"
permissions:
- "app:*"
- "user:*"
- name: "user"
permissions:
- "app:read"
- "app:execute"

数据加密#

加密配置

PRTCL // YAML
加密配置:
enabled: true
at_rest:
algorithm: "AES-256"
key_source: "env"
in_transit:
tls:
enabled: true
min_version: "1.2"

访问控制#

IP 白名单

PRTCL // YAML
IP 白名单:
enabled: true
allowed_ips:
- "192.168.1.0/24"
- "10.0.0.0/8"

性能优化#

缓存策略#

缓存配置

PRTCL // YAML
缓存配置:
enabled: true
provider: "redis" # redis, memory
ttl: 3600 # 1 小时
max_size: 10000

负载均衡#

负载均衡配置

PRTCL // YAML
负载均衡:
enabled: true
strategy: "round_robin" # round_robin, least_connections
health_check:
enabled: true
interval: 30
timeout: 10

数据库优化#

数据库配置

PRTCL // YAML
数据库配置:
pool:
min: 5
max: 20
idle_timeout: 300
query_cache:
enabled: true
size: 1000

故障排查#

常见问题#

发布失败

PRTCL // BASH
Terminal window
# 检查日志
docker logs dify-api
# 检查配置
docker exec dify-api env | grep DATABASE_URL

API 调用失败

PRTCL // BASH
Terminal window
# 测试连接
curl -I https://api.dify.ai/v1
# 检查 API 密钥
echo $DIFY_API_KEY

性能问题

PRTCL // BASH
Terminal window
# 检查资源使用
docker stats dify-api
# 检查数据库连接
docker exec dify-api pg_isready

调试工具#

日志查看

PRTCL // BASH
Terminal window
# 查看应用日志
docker logs -f dify-api
# 查看错误日志
docker logs dify-api | grep ERROR

性能分析

PRTCL // BASH
Terminal window
# 分析 API 响应时间
curl -w "@curl-format.txt" -o /dev/null -s "https://api.dify.ai/v1/completion-messages"

最佳实践#

发布建议#

  • 分阶段发布:先发布到测试环境,再发布到生产环境
  • 版本控制:使用版本号管理发布
  • 灰度发布:逐步放量,监控效果
  • 回滚准备:准备回滚方案

安全建议#

  • 保护密钥:使用环境变量存储密钥
  • 定期轮换:定期更换 API 密钥
  • 监控异常:监控异常访问和行为
  • 权限最小化:最小权限原则

性能建议#

  • 使用缓存:合理使用缓存减少请求
  • 优化数据库:优化查询和索引
  • 负载均衡:使用负载均衡分散流量
  • 监控指标:持续监控性能指标

资源链接#


最后更新: 2026-03-12 作者: EchoHaoRan

R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
// END OF POST

订阅

通过 RSS 订阅本站,新文章发布时第一时间收到通知。

Follow
Classified
Chapter_06
Protocol_Ref: CC-BY-NC-SA-4.0

Dify应用发布和部署

Author: CHONGXIReleased: 2026.04.08

Licensed under CC BY-NC-SA 4.0

评论

© 2025-2026 EchoSpace
Powered by Astro & echohaoran Non-Collaborative_Entity // Protocol_V.4.21