Version v3.7.0 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.
Dify
Dify is a generative AI application innovation engine and open-source LLM application development platform. It provides capabilities from Agent construction to AI workflow orchestration, RAG retrieval, and model management, helping users easily build and operate generative AI-native applications.
Pigsty provides support for self-hosting Dify, allowing you to deploy Dify with a single command while storing critical state in externally managed PostgreSQL. You can use pgvector in the same PostgreSQL instance as a vector database, further simplifying deployment.
Pigsty v3.7.0 ships the Dify v1.8.1 application template.
Quick Start
On a fresh Linux x86 / ARM server running a compatible distribution, execute:
Dify listens on port 5001 by default. You can access it via browser at http://<ip>:5001 and set up your initial user credentials to log in.
After Dify starts, you can install various extensions, configure system models, and begin using it!
Why Self-Host
There are many reasons to self-host Dify, but the primary motivation is data security. The DockerCompose template provided by Dify uses basic default database images, lacking enterprise-grade features like high availability, disaster recovery, monitoring, IaC, and PITR capabilities.
Pigsty elegantly solves these issues for Dify, deploying all components with a single command based on configuration files, and using mirrors to resolve China region access challenges. This makes Dify deployment and delivery incredibly smooth. It handles PostgreSQL master database, PGVector vector database, MinIO object storage, Redis, Prometheus monitoring, Grafana visualization, Nginx reverse proxy, and free HTTPS certificates in one go.
Pigsty ensures all Dify state is stored in externally managed services, including metadata in PostgreSQL and other data in the filesystem. Therefore, the Dify instance launched via Docker Compose becomes a stateless application that can be destroyed and rebuilt at any time, greatly simplifying operations.
Installation
Let’s start with single-node Dify deployment. We’ll cover production high-availability deployment methods later.
First, use Pigsty’s standard installation process to install the PostgreSQL instance required by Dify:
When you use the ./configure -c app/dify command, Pigsty automatically generates the configuration file based on the conf/app/dify.yml
template and your current environment. You should modify passwords, domain, and other relevant parameters in the generated pigsty.yml configuration file
according to your actual needs, then use ./install.yml to execute the standard installation process.
Next, run docker.yml to install Docker and Docker Compose,
then use app.yml to complete Dify deployment:
You can access the Dify Web management interface at http://<your_ip_address>:5001 on your local network.
Default username, email, and password will be prompted for setup on first login.
You can also use the locally resolved placeholder domain dify.pigsty, or follow the configuration below to use a real domain with HTTPS certificates.
Configuration
When you use the ./configure -c app/dify command for configuration,
Pigsty automatically generates the configuration file based on the conf/app/dify.yml template and your current environment.
Here’s a detailed explanation of the default configuration:
Checklist
Here’s a checklist of configuration items you need to focus on:
- Hardware/Software: Prepare required machine resources: Linux
x86_64/arm64server, fresh installation of mainstream Linux operating systems - Network/Permissions: SSH passwordless login access, user has passwordless sudo privileges
- Ensure machine has static IPv4 network address in internal network and can access internet
- If accessing via public network, ensure you have an available domain name pointing to the current node’s public IP address
- Ensure using
app/difyconfig template and modify parameters as neededconfigure -c app/dify, and enter node’s internal primary IP address, or specify via-i <primary_ip>command line parameter
- Have you modified all password-related configuration parameters?【Optional】
grafana_admin_password:pigsty, Grafana admin passwordpg_admin_password:DBUser.DBA, PG superuser passwordpg_monitor_password:DBUser.Monitor, PG monitoring user passwordpg_replication_password:DBUser.Replicator, PG replication user passwordpatroni_password:Patroni.API, Patroni HA component passwordhaproxy_admin_password:pigsty, Load balancer management password
- Have you modified PostgreSQL cluster business user passwords and app configurations using these passwords?
- Default username
difyand passworddifyai123456are generated by Pigsty for Dify, please modify according to actual situation - In Dify’s configuration block, please modify
DB_USERNAME,DB_PASSWORD,PGVECTOR_USER,PGVECTOR_PASSWORDand other parameters accordingly
- Default username
- Have you modified Dify’s default encryption key?
- You can use
openssl rand -base64 42to randomly generate a password string and fill it in theSECRET_KEYparameter
- You can use
- Have you modified the domain used by Dify?
- Replace placeholder domain
dify.pigstywith your actual domain, e.g.dify.pigsty.cc - You can use
sed -ie 's/dify.pigsty/dify.pigsty.cc/g' pigsty.ymlto modify Dify’s domain
- Replace placeholder domain
Domain & SSL
If you want to use a real domain with HTTPS certificates, you need to modify in the pigsty.yml configuration file:
infra_portalparameter’sdifydomain- Best to specify an email address
certbot_emailfor receiving certificate expiration notifications - Configure Dify’s
NGINX_SERVER_NAMEparameter to specify your actual domain
Use the following command to apply for Nginx certificates:
Execute app.yml playbook to redeploy Dify service to make NGINX_SERVER_NAME configuration take effect.
File Backup
You can use restic to back up Dify’s filesystem. Dify’s data files are in the /data/dify directory. You can use the following commands to backup:
After creating the Restic backup repository, you can use the following commands to backup Dify:
Another more reliable way is to use JuiceFS to mount MinIO object storage to the /data/dify directory, so you can use MinIO/S3 to store file state.
If you want to store all data in PostgreSQL, consider “Using JuiceFS to store filesystem data in PostgreSQL”
For example, you can create another dify_fs database and use it as JuiceFS’s metadata storage: