Dify 基于源码本地启动开发

dify源码环境搭建 说明:一般用poetry install都能安装python依赖,安装过程出错,检查系统是否支持改python版本,不支持可以单独安装依赖,然后再执行poetry install。确认 PostgreSQL 版本和安装路径:确认你的 PostgreSQL 服务器版本和安装路径是否正确。说明:gcc版本4.8.5太低,所以找了兼容低版本的nodejs包,如果需要换其他nodejs包,可能需要升级gcc版本。在安装PostgreSQL服务器后,需要初始化数据库集群,即创建一个数据库实例。 阅读详情

Dify 是一个多模块组成的开源 AI 应用开发平台,其代码仓库包含了多个子项目和服务模块。由于其架构复杂度较高,初次接触时可能难以快速理清各部分之间的关系以及正确的本地部署流程。因此下面将详细介绍如何从 GitHub 获取最新源码并正确地搭建起完整的本地开发环境。

代码仓库地址

仓库地址说明
https://github.com/langgenius/difyweb、api 服务
https://github.com/langgenius/dify-plugin-daemonplugin 插件服务,需要在Linux 运行
https://github.com/langgenius/dify-sandboxsandbox 服务,运行python 代码、nodejs代码需要在 Linux 运行

部署架构图

在这里插入图片描述
图片来源 :https://github.com/langgenius/dify/blob/main/docker/docker-compose.png

本地开发启动 只需要其启动 web、api、plugin、sandbox、api服务相关定时任务

环境准备

  1. 操作系统,Linux 开发机,dify-plugin、dify-sandbox 需要在 Linux 运行
  2. 集成开发环境,推荐使用 vscode
  3. 安装 nodejs、uv、go,配置相关镜像源
$ npm config set registry https://registry.npmmirror.com/
$ npm config get registry
https://registry.npmmirror.com/
$ cat /etc/uv/uv.toml 
[[index]]
url = "https://repo.huaweicloud.com/repository/pypi/simple/"
default = true
$ go env GOPROXY
https://goproxy.cn,direct
  1. 数据库、redis

启动服务

sandbox

步骤

  1. git clone https://github.com/langgenius/dify-sandbox && cd dify-sandbox
  2. 运行 ./install.sh 安装必须的依赖
  3. 运行 ./build/build_[amd64|arm64].sh 构建启动服务
  4. 运行 ./main to 启动服务

遇到的问题

无权限创建文件夹
$ ./main
{"time":"2026-04-11T17:11:15.697504499+08:00","level":"INFO","msg":"initializing nodejs runner environment"}
{"time":"2026-04-11T17:11:15.697995589+08:00","level":"ERROR","msg":"failed to create lib path","path":"/var/sandbox/sandbox-nodejs"}
panic: failed to create /var/sandbox/sandbox-nodejs
$ mkdir -p /var/sandbox/sandbox-nodejs
mkdir: cannot create directory ‘/var/sandbox’: Permission denied

创建目录 && 授予权限

$ sudo mkdir -p /var/sandbox && sudo chown -R $USER:$USER /var/sandbox
启动告警信息
"time":"2026-04-11T17:19:00.340491426+08:00","level":"WARN","msg":"python lib path is not available","path":"/opt/python/lib/python3.14"}
{"time":"2026-04-11T17:19:00.340521999+08:00","level":"WARN","msg":"python lib path is not available","path":"/usr/local/lib/python3.14"}
{"time":"2026-04-11T17:19:00.340541807+08:00","level":"WARN","msg":"python lib path is not available","path":"/usr/lib/python3.14"}

问题代码位置

func PreparePythonDependenciesEnv() error {
	config := static.GetDifySandboxGlobalConfigurations()

	runner := runner.TempDirRunner{}
	err := runner.WithTempDir("/", []string{}, func(root_path string) error {
		err := os.WriteFile(path.Join(root_path, "env.sh"), []byte(env_script), 0755)
		if err != nil {
			return err
		}

		for _, lib_path := range config.PythonLibPaths {
			// check if the lib path is available
			if _, err := os.Stat(lib_path); err != nil {
				slog.Warn("python lib path is not available", "path", lib_path)
				continue
			}
			exec_cmd := exec.Command(
				"bash",
				path.Join(root_path, "env.sh"),
				lib_path,
				LIB_PATH,
			)
			exec_cmd.Stderr = os.Stderr

			if err := exec_cmd.Run(); err != nil {
				return err
			}
		}

		os.RemoveAll(root_path)
		return nil
	})

	return err
}

优先获取环境变量的配置,环境变量未配置再获取 yaml 的配置,如果 yaml 未配置,获取硬编码的配置

	python_lib_path := os.Getenv("PYTHON_LIB_PATH")
	if python_lib_path != "" {
		difySandboxGlobalConfigurations.PythonLibPaths = strings.Split(python_lib_path, ",")
	}

	if len(difySandboxGlobalConfigurations.PythonLibPaths) == 0 {
		difySandboxGlobalConfigurations.PythonLibPaths = DEFAULT_PYTHON_LIB_REQUIREMENTS
	}
var DEFAULT_PYTHON_LIB_REQUIREMENTS = []string{
	"/opt/python/lib/python3.14",
	"/usr/local/lib/python3.14",
	"/usr/lib/python3.14",
	"/usr/lib/python3",
	"/usr/lib/x86_64-linux-gnu",
	"/etc/ssl/certs/ca-certificates.crt",
	"/etc/nsswitch.conf",
	"/etc/hosts",
	"/etc/resolv.conf",
	"/run/systemd/resolve/stub-resolv.conf",
	"/run/resolvconf/resolv.conf",
	"/etc/localtime",
	"/usr/share/zoneinfo",
	"/etc/timezone",
}

修改 yaml 的配置,移除多余的路径包,修改之后的配置 增加了 python_lib_path

$ cat conf/config.yaml
app:
  port: 8194
  debug: True
  key: dify-sandbox
max_workers: 4
max_requests: 50
worker_timeout: 5
python_path: /opt/python/bin/python3
python_lib_path:
  - "/usr/lib/python3"
  - "/usr/lib/x86_64-linux-gnu"
  - "/usr/lib/aarch64-linux-gnu"
  - "/etc/ssl/certs/ca-certificates.crt"
  - "/etc/nsswitch.conf"
  - "/etc/hosts"
  - "/etc/resolv.conf"
  - "/run/systemd/resolve/stub-resolv.conf"
  - "/run/resolvconf/resolv.conf"
  - "/etc/localtime"
  - "/usr/share/zoneinfo"
  - "/etc/timezone"
enable_network: True # please make sure there is no network risk in your environment
enable_preload: False # please keep it as False for security purposes
log_path: "./logs" # path to store log files, default is "./logs"
allowed_syscalls: # please leave it empty if you have no idea how seccomp works
proxy:
  socks5: ''
  http: ''
  https: ''

再次启动服务

rm -rf /var/sandbox/* && ./main
{"time":"2026-04-11T17:48:25.609912649+08:00","level":"INFO","msg":"initializing nodejs runner environment"}
{"time":"2026-04-11T17:48:25.654258127+08:00","level":"INFO","msg":"nodejs runner environment initialized"}
{"time":"2026-04-11T17:48:25.654752995+08:00","level":"INFO","msg":"initializing python runner environment"}
{"time":"2026-04-11T17:48:25.655969634+08:00","level":"INFO","msg":"python runner environment initialized"}
{"time":"2026-04-11T17:48:25.65709941+08:00","level":"INFO","msg":"network has been enabled"}
{"time":"2026-04-11T17:48:25.657143329+08:00","level":"INFO","msg":"config init success"}
{"time":"2026-04-11T17:48:25.657244961+08:00","level":"INFO","msg":"runner dependencies init success"}
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /health                   --> github.com/langgenius/dify-sandbox/internal/controller.Setup.func1 (5 handlers)
{"time":"2026-04-11T17:48:25.657340263+08:00","level":"INFO","msg":"setting max requests","max":50}
{"time":"2026-04-11T17:48:25.657363705+08:00","level":"INFO","msg":"setting max workers","max":4}
[GIN-debug] POST   /v1/sandbox/run           --> github.com/langgenius/dify-sandbox/internal/controller.RunSandboxController (9 handlers)
[GIN-debug] GET    /v1/sandbox/dependencies  --> github.com/langgenius/dify-sandbox/internal/controller.GetDependencies (6 handlers)
[GIN-debug] POST   /v1/sandbox/dependencies/update --> github.com/langgenius/dify-sandbox/internal/controller.UpdateDependencies (6 handlers)
[GIN-debug] GET    /v1/sandbox/dependencies/refresh --> github.com/langgenius/dify-sandbox/internal/controller.RefreshDependencies (6 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on :8194
{"time":"2026-04-11T17:48:25.657378554+08:00","level":"INFO","msg":"installing python dependencies"}
{"time":"2026-04-11T17:48:25.657470953+08:00","level":"INFO","msg":"python dependencies installed"}
{"time":"2026-04-11T17:48:25.657493653+08:00","level":"INFO","msg":"initializing python dependencies sandbox"}
{"time":"2026-04-11T17:50:05.341354813+08:00","level":"INFO","msg":"python dependencies sandbox initialized"}

检查服务是否可用

$ curl http://localhost:8194/health
"ok"

测试代码执行

curl -X POST http://localhost:8194/v1/sandbox/run \
  -H "Content-Type: application/json" \
  -H "X-Api-Key: dify-sandbox" \
  -d '{
    "language": "python3",
    "code": "import json\nperson = {\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}\njson_str = json.dumps(person)\nprint(json_str)",
    "preload": "",
    "enable_network": false
  }'
{"code":-500,"message":"chown script to uid 10003: operation not permitted","data":null}

定位到问题代码

	if err = syscall.Chown(untrustedCodePath, uid, static.SANDBOX_GROUP_ID); err != nil {
		os.Remove(untrustedCodePath)
		return "", "", fmt.Errorf("chown script to uid %d: %w", uid, err)
	}

要执行 chown 命令,如何给普通用户授权? 暂时切换到 root 运行吧

# rm -rf /var/sandbox/* && ./main

再次执行测试代码,报错

$ curl -X POST http://localhost:8194/v1/sandbox/run \
  -H "Content-Type: application/json" \
  -H "X-Api-Key: dify-sandbox" \
  -d '{
    "language": "python3",
    "code": "import json\nperson = {\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}\njson_str = json.dumps(person)\nprint(json_str)",
    "preload": "",
    "enable_network": false
  }'
{"code":-500,"message":"fork/exec /opt/python/bin/python3: no such file or directory","data":null}

问题代码

	// create a new process
	cmd := exec.Command(
		configuration.PythonPath,
		untrustedCodePath,
		LIB_PATH,
		key,
	)

python 的路径不对,需要修改 yaml 的配置

$ which python3
/usr/bin/python3

修改后的 yaml

$ cat ./conf/config.yaml 
app:
  port: 8194
  debug: True
  key: dify-sandbox
max_workers: 4
max_requests: 50
worker_timeout: 5
python_path: /usr/bin/python3
nodejs_path: /usr/local/node-v24.14.1/bin/node
python_lib_path:
  - "/usr/lib/python3"
  - "/usr/lib/x86_64-linux-gnu"
  - "/etc/ssl/certs/ca-certificates.crt"
  - "/etc/nsswitch.conf"
  - "/etc/hosts"
  - "/etc/resolv.conf"
  - "/etc/localtime"
  - "/usr/share/zoneinfo"
  - "/etc/timezone"
enable_network: True # please make sure there is no network risk in your environment
enable_preload: False # please keep it as False for security purposes
log_path: "./logs" # path to store log files, default is "./logs"
allowed_syscalls: # please leave it empty if you have no idea how seccomp works
proxy:
  socks5: ''
  http: ''
  https: ''

最终的测试脚本

$ cat test_dify_sandbox.sh 
#!/bin/bash

# 健康检查接口
echo "健康检查接口:"
curl http://localhost:8194/health

# Python3 示例
echo "\nPython3 示例:"
curl -X POST http://localhost:8194/v1/sandbox/run \
  -H "Content-Type: application/json" \
  -H "X-Api-Key: dify-sandbox" \
  -d '{
    "language": "python3",
    "code": "import json\nperson = {\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}\njson_str = json.dumps(person)\nprint(json_str)",
    "preload": "",
    "enable_network": false
  }'

echo "\nNode.js 示例:"
# Node.js 示例
curl -X POST http://localhost:8194/v1/sandbox/run \
  -H "Content-Type: application/json" \
  -H "X-Api-Key: dify-sandbox" \
  -d '{
    "language": "nodejs",
    "code": "const person = {name: \"John\", age: 30, city: \"New York\"};\nconst jsonString = JSON.stringify(person);\nconsole.log(jsonString);",
    "preload": "",
    "enable_network": false
  }'

运行结果

$ sh test_dify_sandbox.sh 
健康检查接口:
"ok"
Python3 示例:
{"code":0,"message":"success","data":{"error":"","stdout":"{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}\n"}}
Node.js 示例:
{"code":0,"message":"success","data":{"error":"","stdout":"{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}\n"}}

plugin

步骤

  1. 将.env.example文件复制到.env中,并设置正确的环境变量,如DB_HOST等。
cp .env.example .env

本地运行使用的是 mysql、redis, 修改如下配置

# redis
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=difyai123456
REDIS_DB=0
REDIS_USE_SSL=false

DB_TYPE=mysql
DB_USERNAME=root
DB_PASSWORD=difyai123456
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=dify_plugin
  1. 使用以下命令运行守护进程。它会使用godotenv从.env文件中加载环境变量
$ go run github.com/joho/godotenv/cmd/godotenv@latest -f .env go run cmd/server/main.go
2026-04-11T11:55:52.702513374Z INFO dify-plugin-daemon pool.go:34 init routine pool size=1024
2026-04-11T11:55:52.707063438Z INFO dify-plugin-daemon init.go:120 dify plugin db initialized
2026-04-11T11:55:52.707154132Z INFO dify-plugin-daemon manager.go:118 start plugin manager daemon
2026-04-11T11:55:52.708809889Z INFO dify-plugin-daemon init.go:20 persistence initialized
2026-04-11T11:55:52.708828438Z INFO dify-plugin-daemon server_local.go:16 start to handle new plugins path=plugin
2026-04-11T11:55:52.708861823Z INFO dify-plugin-daemon server_local.go:17 launch plugins with max concurrency concurrency=2
2026-04-11T11:55:52.709168884Z INFO dify-plugin-daemon logger.go:27 Launching gnet with 8 event-loops, listening on: tcp://127.0.0.1:5003
2026-04-11T11:55:52.733288393Z INFO dify-plugin-daemon middleware.go:83 trace_id=d6aa3960923e78b44ac37c837d638d11 HTTP request latency_ms=0 client_ip=192.168.1.3 method=GET path=/health/check status=200
2026-04-11T11:55:52.733564699Z INFO dify-plugin-daemon middleware.go:83 trace_id=b43e116a9ca6ae652a81e129ad764caf HTTP request client_ip=192.168.1.3 method=GET path=/health/check status=200 latency_ms=0
2026-04-11T11:55:52.733694625Z INFO dify-plugin-daemon middleware.go:83 trace_id=127a5dd66ed7b1359088037db49e1343 HTTP request status=200 latency_ms=0 client_ip=192.168.1.3 method=GET path=/health/check
2026-04-11T11:55:52.733918034Z INFO dify-plugin-daemon middleware.go:83 trace_id=a9482958069272bee9e966bad6f47b5b HTTP request method=GET path=/health/check status=200 latency_ms=0 client_ip=192.168.1.3
2026-04-11T11:55:52.734122273Z INFO dify-plugin-daemon middleware.go:83 trace_id=ae698a286869db594f28c6fcc654b413 HTTP request method=GET path=/health/check status=200 latency_ms=0 client_ip=192.168.1.3
2026-04-11T11:55:52.73425572Z INFO dify-plugin-daemon middleware.go:83 trace_id=82b83bb68fd3d9a4d5976dbb2c71d783 HTTP request client_ip=192.168.1.3 method=GET path=/health/check status=200 latency_ms=0
2026-04-11T11:55:53.210279248Z INFO dify-plugin-daemon cluster_lifetime.go:114 current node has become the master of the cluster
2026-04-11T11:56:02.75499235Z INFO dify-plugin-daemon node.go:248 node has been removed from the cluster due to being disconnected node_id=ff0be83a-d227-474d-bd7a-259cc3ab6383

检查服务是否可用

$ curl http://localhost:5002/health/check
{"active_dispatch_requests":0,"active_requests":1,"build_time":"","platform":"local","pool_status":{"free":1024,"busy":0,"total":1024},"status":"ok","version":""}

api、web

步骤

  1. 运行初始化脚本复制配置文件,安装依赖, 在项目根目录执行
$ ./dev/setup

检查 api/.env, web/.env.local, 和 docker/middleware.env 文件是否生成了

  1. 修改 api/.env 配置
    生成 SECRET_KEY
sed -i "/^SECRET_KEY=/c\\SECRET_KEY=$(openssl rand -base64 42)" ./api/.env

在这里插入图片描述
修改 数据库、redis 配置

# redis configuration
REDIS_HOST=localhost
REDIS_PORT=6379
# Optional: limit total connections in connection pool (unset for default)
# REDIS_MAX_CONNECTIONS=200
REDIS_USERNAME=
REDIS_PASSWORD=difyai123456
REDIS_USE_SSL=false
# SSL configuration for Redis (when REDIS_USE_SSL=true)
REDIS_SSL_CERT_REQS=CERT_NONE
# Options: CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED
REDIS_SSL_CA_CERTS=
# Path to CA certificate file for SSL verification
REDIS_SSL_CERTFILE=
# Path to client certificate file for SSL authentication
REDIS_SSL_KEYFILE=
# Path to client private key file for SSL authentication
REDIS_DB=11

# Database configuration
DB_TYPE=mysql
DB_USERNAME=root
DB_PASSWORD=difyai123456
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=dify
  1. 启动api服务
./dev/start-api

运行 uv run flask db upgrade 报错

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1049, "Unknown database 'dify'")

创建相关数据库

mysql> create database dify charset=utf8mb4;
Query OK, 1 row affected (0.00 sec)

再次运行 ./dev/start-api

$ ./dev/start-api
+++ realpath ./dev/start-api
++ dirname /home/scd/code/go/dify/dify-main/dev/start-api
+ SCRIPT_DIR=/home/scd/code/go/dify/dify-main/dev
+ cd /home/scd/code/go/dify/dify-main/dev/../api
+ uv run flask db upgrade
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
....
INFO  [alembic.runtime.migration] Running upgrade 0ec65df55790 -> 6b5f9f8b1a2c, add user_id and switch workflow_draft_variables unique key to user scope
+ uv run flask run --host 0.0.0.0 --port=5001 --debug
 * Debug mode: on
2026-04-11 12:28:00,84 INFO [_internal.py:97]  WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5001
 * Running on http://192.168.1.3:5001
2026-04-11 12:28:00,84 INFO [_internal.py:97]  Press CTRL+C to quit
2026-04-11 12:28:00,84 INFO [_internal.py:97]   * Restarting with stat
2026-04-11 12:28:09,719 WARNING [_internal.py:97]   * Debugger is active!
2026-04-11 12:28:09,727 INFO [_internal.py:97]   * Debugger PIN: 121-693-603

测试健康检测接口

curl http://localhost:5001/health
{"pid": 1103970, "status": "ok", "version": "1.13.3"}
  1. 启动web服务
$ ./dev/start-web
+++ realpath ./dev/start-web
++ dirname /home/scd/code/go/dify/dify-main/dev/start-web
+ SCRIPT_DIR=/home/scd/code/go/dify/dify-main/dev
++ dirname /home/scd/code/go/dify/dify-main/dev
+ ROOT_DIR=/home/scd/code/go/dify/dify-main
+ pnpm --dir /home/scd/code/go/dify/dify-main install
 WARN  Unsupported engine: wanted: {"node":"^22.22.1"} (current: {"node":"v24.14.1","pnpm":"10.33.0"})
Scope: all 5 workspace projects
Lockfile is up to date, resolution step is skipped
Already up to date
. prepare$ vp config
└─ Done in 146ms
Done in 1.9s using pnpm v10.33.0
+ pnpm --dir /home/scd/code/go/dify/dify-main/web dev:inspect

> dify-web@1.13.3 dev:inspect /home/scd/code/go/dify/dify-main/web
> next dev --inspect

Debugger listening on ws://127.0.0.1:9229/8029ada1-9c26-48fc-9393-50ebaa3734f4
For help, see: https://nodejs.org/en/docs/inspector
▲ Next.js 16.2.3 (Turbopack)
- Local:         http://localhost:3000
- Network:       http://192.168.1.3:3000
- Debugger port: 9229
- Environments: .env.local
✓ Ready in 445ms
Starting inspector on 127.0.0.1:9229 failed: address already in use
Starting inspector on 127.0.0.1:9229 failed: address already in use
- Experiments (use with caution):
  ⨯ turbopackFileSystemCacheForDev

浏览器访问 http://localhost:3000 首次访问需要等一会儿
在这里插入图片描述
设置管理员账户之后跳转到工作空间
在这里插入图片描述

检查相关数据表

mysql> select * from dify_setups;
+---------+---------------------+
| version | setup_at            |
+---------+---------------------+
| 1.13.3  | 2026-04-11 12:38:08 |
+---------+---------------------+
1 row in set (0.01 sec)

mysql> select id,name,plan,status from tenants;
+--------------------------------------+-----------------+-------+--------+
| id                                   | name            | plan  | status |
+--------------------------------------+-----------------+-------+--------+
| 8b1e249c-2812-4114-8d5d-a3ddc357652f | scd's Workspace | basic | normal |
+--------------------------------------+-----------------+-------+--------+
1 row in set (0.00 sec)

mysql> select id,name,interface_language,interface_theme,timezone from accounts;
+--------------------------------------+------+--------------------+-----------------+---------------+
| id                                   | name | interface_language | interface_theme | timezone      |
+--------------------------------------+------+--------------------+-----------------+---------------+
| f7c5cd88-1b5d-49a1-b949-2b6b5d33358a | scd  | zh-Hans            | light           | Asia/Shanghai |
+--------------------------------------+------+--------------------+-----------------+---------------+
1 row in set (0.00 sec)

mysql> select tenant_id,account_id,role,invited_by from tenant_account_joins;
+--------------------------------------+--------------------------------------+-------+------------+
| tenant_id                            | account_id                           | role  | invited_by |
+--------------------------------------+--------------------------------------+-------+------------+
| 8b1e249c-2812-4114-8d5d-a3ddc357652f | f7c5cd88-1b5d-49a1-b949-2b6b5d33358a | owner | NULL       |
+--------------------------------------+--------------------------------------+-------+------------+
1 row in set (0.00 sec)

注意事项

本地开发,机器吃不消了,Celery 任务队列没有启动
在这里插入图片描述

supervisord 一次启动多个服务

  1. 目录结构
$ tree -L 1
.
├── dify-main
├── dify-plugin-daemon
├── dify-sandbox
├── docker-compose.yml
├── env-check.sh
├── logs
├── process_problem.txt
├── run
├── supervisord.conf
├── test_dify_api.sh
├── test_dify_plugin.sh
└── test_dify_sandbox.sh

6 directories, 7 files

$ tree dify-main -d -L 1
dify-main
├── api
├── dev
├── docker
├── docs
├── e2e
├── images
├── node_modules
├── packages
├── scripts
├── sdks
└── web

12 directories
仓库地址说明文件夹
https://github.com/langgenius/difyweb、api 服务dify-main/api 、dify-main/web
https://github.com/langgenius/dify-plugin-daemonplugin 插件服务,需要在Linux 运行dify-plugin-daemon
https://github.com/langgenius/dify-sandboxsandbox 服务,运行python 代码、nodejs代码需要在 Linux 运行dify-sandbox
  1. supervisord.conf 配置文件, logs、run 文件夹需要手动创建
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Quotes around values are not supported, except in the case of
;    the environment= options as shown below.
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
;  - Command will be truncated if it looks like a config file comment, e.g.
;    "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".
;
; Warning:
;  Paths throughout this example file use /tmp because it is available on most
;  systems.  You will likely need to change these to locations more appropriate
;  for your system.  Some systems periodically delete older files in /tmp.
;  Notably, if the socket file defined in the [unix_http_server] section below
;  is deleted, supervisorctl will be unable to connect to supervisord.

[unix_http_server]
file=./run/supervisor.sock   ; the path to the socket file
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

; Security Warning:
;  The inet HTTP server is not enabled by default.  The inet HTTP server is
;  enabled by uncommenting the [inet_http_server] section below.  The inet
;  HTTP server is intended for use within a trusted environment only.  It
;  should only be bound to localhost or only accessible from within an
;  isolated, trusted network.  The inet HTTP server does not support any
;  form of encryption.  The inet HTTP server does not use authentication
;  by default (see the username= and password= options to add authentication).
;  Never expose the inet HTTP server to the public internet.

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

[supervisord]
logfile=./logs/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=debug                ; log level; default info; others: debug,warn,trace
pidfile=./run/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false               ; start in foreground if true; default false
silent=false                 ; no logs to stdout if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200
;umask=022                   ; process file creation umask; default 022
;user=supervisord            ; setuid to this UNIX account at startup; recommended if root
;identifier=supervisor       ; supervisord identifier, default is 'supervisor'
;directory=/tmp              ; default is not to cd during start
;nocleanup=true              ; don't clean up tempfiles at start; default false
;childlogdir=/tmp            ; 'AUTO' child log dir, default $TEMP
;environment=KEY="value"     ; key value pairs to add to environment
;strip_ansi=false            ; strip ansi escape codes in logs; def. false

; The rpcinterface:supervisor section must remain in the config file for
; RPC (supervisorctl/web interface) to work.  Additional interfaces may be
; added by defining them in separate [rpcinterface:x] sections.

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

; The supervisorctl section configures how supervisorctl will connect to
; supervisord.  configure it match the settings in either the unix_http_server
; or inet_http_server section.

[supervisorctl]
serverurl=unix://./run/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available


; The sample program section below shows all possible program subsection values.
; Create one or more 'real' program: sections to be able to control them under
; supervisor.

[program:dify-sandbox]
command=go run cmd/server/main.go             ; the program (relative uses PATH, can take args)
process_name=dify-sandbox   ; process_name expr (default %(program_name)s)
directory=./dify-sandbox                ; directory to cwd to before exec (def no cwd)
priority=10                  ; the relative start priority (default 999)
stdout_logfile=./logs/dify-sandbox.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
stderr_logfile=./logs/dify-sandbox-error.log        ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;environment=A="1",B="2"       ; process environment additions (def no adds)


[program:dify-plugin]
command=go run github.com/joho/godotenv/cmd/godotenv@latest -f .env go run cmd/server/main.go             ; the program (relative uses PATH, can take args)
process_name=dify-plugin   ; process_name expr (default %(program_name)s)
directory=./dify-plugin-daemon                ; directory to cwd to before exec (def no cwd)
priority=20                  ; the relative start priority (default 999)
stdout_logfile=./logs/dify-plugin.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
stderr_logfile=./logs/dify-plugin-error.log        ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;environment=A="1",B="2"       ; process environment additions (def no adds)

[program:dify-api]
command=uv run flask run --host 0.0.0.0 --port=5001             ; the program (relative uses PATH, can take args)
process_name=dify-api   ; process_name expr (default %(program_name)s)
directory=./dify-main/api                ; directory to cwd to before exec (def no cwd)
priority=30                  ; the relative start priority (default 999)
stdout_logfile=./logs/dify-api.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
stderr_logfile=./logs/dify-api-error.log        ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;environment=A="1",B="2"       ; process environment additions (def no adds)

[program:dify-web]
command=pnpm -C web run start            ; the program (relative uses PATH, can take args)
process_name=dify-web   ; process_name expr (default %(program_name)s)
directory=./dify-main                ; directory to cwd to before exec (def no cwd)
priority=40                  ; the relative start priority (default 999)
stdout_logfile=./logs/dify-web.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
stderr_logfile=./logs/dify-web-error.log        ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;environment=A="1",B="2"       ; process environment additions (def no adds)

pnpm -C web run start 使用编译好的文件启动前端,访问会流畅点
在这里插入图片描述

  1. 启动命令
supervisord -c supervisord.conf
  1. 查看服务状态
$ supervisorctl status all
dify-api                         RUNNING   pid 861948, uptime 0:37:38
dify-plugin                      RUNNING   pid 927281, uptime 0:26:38
dify-sandbox                     RUNNING   pid 861946, uptime 0:37:38
dify-web                         RUNNING   pid 923249, uptime 0:34:53
Dify本地源码启动教程 Dify本地源码启动教程. 阅读详情

相关推荐

Dify源码启动指南:从零搭建本地开发环境,深入掌握开源LLM平台架构

大模型应用的工程化落地,离不开稳定可扩展的开源平台支撑。Dify作为高热度开源LLM应用开发框架,容器化部署虽能快速体验,却隐藏了内部实现细节。源码启动则能完整呈现Flask后端、Next.js前端与Celery异步任务三大进程的协作原理,让开发者在真实的代码链路中理解环境变量配置、数据库迁移、前后端联调等核心环节。这种源码级掌控能力,对二次开发、私有化部署及深度集成具有重要价值——无论是调试工作流节点,还是自定义模型接入,都能大幅提升效率。基于本地环境实践,系统梳理Dify源码启动的完整流程与避坑要点,帮

weixin_33178839的博客 320

dify的2种部署方式(源码/开发环境部署)

Dify部署手册(源码/开发环境部署),从接触dify用时5天,完成部署,希望对入坑的小伙伴们有所帮助。

spring_snow_的博客 1万+

Dify入门-本地部署dify

Dify 是一个开源的 AI 应用开发框架,专为构建和部署基于大语言模型(LLM)的生成式 AI 应用而设计,结合后端即服务(BaaS)和 LLMOps 理念,提供从开发到运维的全生命周期管理能力,支持快速构建生产级 AI 应用

weixin_43163457的博客 1239

从零开始之Dify源码部署篇

Dify传送门。本系列文章从零开始探索Dify的功能及搭建过程。本文的搭建流程是基于本地源码进行部署。Dify Docker Compose部署篇传送门。

u013563715的博客 3万+

本地 Docker 部署 Dify 教程

是一款开源的 LLM 应用开发平台,提供可视化工作流、API 接口和模型管理等功能,非常适合快速构建 AI 应用。本教程将介绍如何在本地通过部署 Dify。

qq_62024906的博客 847

大模型应用开发平台-Dify介绍和本地部署教程

大模型应用开发平台dify的介绍以及本地部署教程

leonhongliang806的博客 1170

Dify源码本地启动实战:从0到1跑通前后端开发环境

LLM应用开发平台正成为企业搭建知识库问答、工作流编排与Agent应用的基础设施,而Dify作为开源代表,其灵活的二次开发能力深受开发者关注。与依赖docker compose黑盒启动不同,源码方式能让你直接修改后端Flask与前端Next.js代码,配合断点调试与热更新,真正理解平台内部机制。本文从环境准备、依赖安装、中间件配置到数据库迁移,系统梳理Dify本地启动的关键步骤,并针对常见报错给出排查思路。无论是内网私有化定制,还是深度功能扩展,掌握源码启动方法都能显著提升开发效率,让团队摆脱容器隔离的束缚

weixin_33600816的博客 159

让AI转化为生产力,Dify 私有化部署 + 接入Ollama部署本地模型。

(1)Dify官方释义 工作流是通过将复杂的任务分解成较小的步骤(节点)降低系统复杂度,减少了对提示词技术和模型推理能力的依赖,提高了 LLM 应用面向复杂任务的性能,提升了系统的可解释性、稳定性和容错性。我是渔夫,是一名程序员,现已 All in AI,努力探索小而美的AI商业模式、包括AI副业、个人IP、分享技术、非科班转码经验等相关文章,欢迎关注,和渔夫一起成长。优点:把目标场景的任务分解成多个节点,每个节点完成一个任务,然后通过数据流连接起来,其确保逻辑清晰易懂,提升了结果的准确性。

渔夫.AI 1335

【人工智能agent】--docker本地部署dify教程

Dify 是一款开源的大语言模型(LLM) 应用开发平台。它融合了后端即服务(Backend as Service)和 LLMOps 的理念,使开发者可以快速搭建生产级的生成式 AI 应用。即使你是非技术人员,也能参与到 AI 应用的定义和数据运营过程中。 非技术人员:不懂编程、对大模型不太懂,也可以使用DIFY2、功能介绍 由于 Dify 内置了构建 LLM 应用所需的关键技术栈,包括对数百个模型的支持、直观的 Prompt 编排界面、高质量的 RAG 引擎、稳健的 Agen

我是个好人呀,O(∩_∩)O 2万+

01_Dify开源版使用源代码本地启动

本文提供了在Windows环境下本地部署Dify AI平台的详细图文教程。部署过程主要包括:检查硬件要求,安装Docker、Git等前置依赖;克隆Dify指定版本代码仓库;使用Conda创建Python 3.12虚拟环境;分别启动API后端服务(包含数据库迁移和依赖安装)、Worker异步任务服务以及基于Node.js的前端Web服务。文章还涵盖了环境变量配置、管理员账户设置,并针对本地部署中常见的插件守护进程通信错误提供了解决方案。最终用户可通过浏览器访问本地地址,完成Dify平台的安装与初始配置。

在科技的浪潮中,我们寻找着创新的火种,在代码的海洋里,我们编织着智慧的网。腾飞开源,就是这样一个由技术精英汇聚而成的博客平台,我们致力于分享在Java、Python、IoT和人工智能等领域的最新研究成果和实战经验。 在腾飞开源的博客上,你会看到紧跟技术前 1918

Dify源码部署,搭建二次开发环境(一)

本文记录了在Windows环境下搭建Dify 1.4.2二次开发环境的完整过程。主要包括:1)基础环境准备(Python 3.12.x、Node.js 18等);2)在CentOS虚拟机中通过Docker启动中间件服务(Redis、PostgreSQL等);3)配置API服务环境,包括修改.env文件、安装uv依赖管理工具、执行数据库迁移;4)启动API服务和Worker服务。文章详细记录了每个步骤的操作命令和可能遇到的问题,特别是针对Windows环境给出了特殊处理建议。

litlit023的专栏 705

Docker+Dify+Ollama实现本地大模型部署

本文详细介绍了Docker环境搭建及Dify、Ollama的本地部署流程。首先讲解了Docker Desktop的下载安装、配置镜像源及验证方法;其次说明Dify源码获取、环境配置和启动步骤;然后介绍Ollama的安装、模型路径设置及本地大模型下载;最后展示如何在Dify工作台关联Ollama本地模型。整个部署过程包含环境配置验证、服务启动检查等关键步骤,最终实现在本地完成Dify智能体开发环境的搭建。

awigu的博客 2708

python监听海康威视报警服务器

因为我使用海康威视摄像头是自带热成像的所以事件报警会上报两张图片,一张是RGB图像、另一张是热成像图像,因此使用。拿到的就是第一张RGB图像。可以点击测试,会显示。

qq_57018478的博客 1157

【详细教程】如何在Ubuntu上本地部署Dify?

摘要:本文介绍了在Ubuntu系统上本地部署Dify开源大语言模型平台的详细步骤。Dify是一个支持多模型(如GPT、Llama等)的低代码AI应用开发平台,提供RAG增强、Agent框架等功能。部署过程包括:1)安装Docker和Docker Compose;2)获取Dify源码并配置环境变量;3)解决国内镜像拉取问题;4)通过docker-compose启动服务。完成部署后,用户可通过localhost访问并初始化管理员账号,快速构建生成式AI应用。文中还提供了常见问题排查方法和常用命令参考。

虫无涯的博客 5820

攻防世界-Reverse-Game

攻防世界,game,逆向

wuh2333的博客 775

工业预测模型避坑指南:PHM2012轴承数据实战中,LSTM、CNN、Transformer到底怎么选?

本文深入探讨了工业预测模型在PHM2012轴承数据下的选型策略,对比了LSTM、CNN和Transformer等主流模型在轴承寿命预测任务中的表现。通过真实实验数据,提供了可复现的选型决策框架,帮助工程师根据数据规模、硬件条件和精度要求选择最佳模型。文章还揭示了工程落地中的隐藏陷阱,如数据不均衡和工况迁移挑战,并提出了解决方案。

weixin_33694172的博客 493

零基础教程:Dify本地部署从安装到使用

通过以上步骤,你应该已经成功在本地部署了Dify。整个过程虽然看起来步骤不少,但其实每一步都很清晰。对于想要快速体验Dify的朋友,我推荐使用InsCode(快马)平台,它提供了现成的环境,可以免去复杂的配置过程,一键就能体验Dify的核心功能。作为一个新手,我最大的感受是Dify的文档很完善,社区也很活跃。如果在部署过程中遇到问题,不妨去官方论坛或GitHub issues区查找解决方案。祝你在Dify的世界里探索愉快!

IndigoNight21的博客 1078

Hadoop实战:用MapReduce分析YouTube视频数据集(附完整代码)

本文提供了一个完整的Hadoop MapReduce实战教程,指导读者使用MapReduce框架分析YouTube视频数据集,统计不同视频类别的数量分布。教程涵盖从数据获取、预处理、HDFS操作到Java代码编写、作业提交及结果可视化的全流程,并附有完整代码,帮助开发者深入理解分布式计算思想。

lilh34434的博客 198

Dify 源码本地部署启动及完整步骤解析

Dify 源码本地部署启动及完整步骤解析

分享实践与思考 2383

PyTorch实战(30)——使用TorchScript和ONNX导出通用PyTorch模型

在本节中,我们将深入探讨使用 TorchScript 导出 PyTorch 模型。通过序列化,TorchScript 使模型与 Python 生态系统独立,从而使得模型可以在其他环境中加载,例如基于 C++ 的环境。我们还跨越 Torch 框架与 Python 生态的边界,研究机器学习通用开放格式 ONNX,该技术能帮助我们将 PyTorch 训练的模型导出至非 PyTorch 甚至非 Python 环境。

盼小辉丶的博客 3520

多个linux系统安装到一块硬盘(Kylin+UOS+ubuntu)

之前写过一篇类似的文档,笔者把kylin和UOS安装在一块硬盘上上一篇的文档地址多个linux系统安装到一块硬盘(Kylin+UOS)_银河麒麟系统和uos安装成双系统-优快云博客本次记录的是三个系统到一块硬件上银河麒麟:Kylin-Desktop-V10-SP1-Release-2107-arm64统信:uniontechos-desktop-20-professional-1050-arm64乌班图:ubuntu-22.04.5-live-server-arm64。

aggs1990的专栏 567

Dify源码部署,搭建二次开发环境(一)Dify入门到精通,收藏这篇就足够了!

最近在研究Dify源码在本地window环境,搭建dify二次开发环境,期间也遇到了各种各样的问题,在这里做一下总结。

2401_82469710的博客 1416

SAP ABAP Web Service 的创建与消费:保姆级教程

SOAP 定义了消息的格式和传输规则,使得 Web Service 可以在不同的操作系统和网络环境中通信。通过 WSDL,服务的提供者可以明确地定义服务的功能,而服务的使用者则可以通过解析 WSDL 文件,了解如何正确地调用该服务。它封装了与 Web 服务通信的所有复杂性,如消息格式的构建、传输协议的选择、请求的发送和响应的处理等。除了本文介绍的 ABAP 编程语言之外,我们还可以通过 Java,Node.js,C++,C#,Python 等其他编程语言来消费本文创建的 ABAP Web Service.

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 713

Dify本地部署完整指南:源码与Docker双模式启动

本文详细介绍Dify的本地部署步骤,涵盖中间件服务搭建及后端前端的源码与Docker两种启动方式,帮助开发者快速构建完整的应用环境。

weixin_42577735的博客 1404

微波技术仿真:微波谐振器分析_(2).微波谐振器理论

谐振器是一种能够在特定频率范围内存储和释放电磁能量的器件。在微波频段,谐振器通常用于滤波、频率选择和能量存储等应用。一个理想的谐振器在谐振频率下能够存储无限大的能量,但在实际应用中,由于损耗的存在,谐振器的性能会受到一定限制。微波谐振器在微波通信、雷达系统、微波测量和微波电路设计等领域中发挥着重要作用。谐振器的设计需要考虑多个因素,包括谐振频率的精确控制、损耗的最小化、频率稳定性的提高和小型化设计。通过理论分析和仿真工具的使用,可以有效优化谐振器的性能,满足实际应用的需求。

2401_87715305的博客 934

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Dify本地部署完整教程:Docker与Git配置指南

通过Docker和Git快速部署Dify 1.4.0版本,涵盖环境搭建、镜像加速、容器启动及常见问题解决,帮助用户顺利完成本地安装并访问管理界面。

weixin_35751412的博客 1302

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

上一篇: dify-plugin api接口文档
下一篇: Docker 重命名数据卷
Chengdu.S
博客等级 码龄9年 283粉丝 86原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Chengdu.S

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值