Deploy Dify AI Platform
Open-source AI application platform with RAG engine, visual workflow builder, and multi-model support
What is Dify?
Dify is a production-ready platform for agentic workflow development that integrates comprehensive model support, RAG pipelines, and agent capabilities. The platform supports hundreds of language models from various providers, including OpenAI, Anthropic, and open-source alternatives. Even non-technical individuals can participate in defining AI applications and managing data operations through its visual interface.
Key Features
- • Visual Workflow Builder
- • Model Agnostic (GPT, Claude, Llama)
- • Built-in RAG Engine
- • Agent Framework with custom tools
- • API-First Design
- • Knowledge Base Management
Why RamNode VPS?
- • High-performance SSD storage
- • Scalable resources
- • Full root access
- • Cost-effective pricing
- • 99.9% uptime SLA
Prerequisites
System Requirements
- • OS: Ubuntu 22.04 or 24.04 LTS
- • CPU: Minimum 2 cores (4+ cores recommended)
- • RAM: Minimum 4GB (8GB+ recommended for production)
- • Storage: At least 20GB available disk space
- • Access: Root or sudo privileges
- • Network: Stable internet connection
💡 Recommended VPS Plan
For optimal Dify performance, we recommend the 4GB Standard Cloud VPS plan. This configuration provides sufficient resources for running multiple AI models, handling concurrent users, and maintaining responsive performance for your AI applications.
Prepare Your Server
Connect to your VPS via SSH and update the system:
# Connect to your VPS
ssh root@your-vps-ip
# Update package lists and upgrade system
sudo apt update && sudo apt upgrade -y
# Install essential packages
sudo apt install -y curl wget git unzipInstall Docker
Remove any conflicting packages:
# Remove conflicting Docker packages
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do
sudo apt-get remove -y $pkg 2>/dev/null || true
doneInstall Docker dependencies:
# Install required packages
sudo apt install -y ca-certificates curl gnupg lsb-release apt-transport-https software-properties-commonAdd Docker's official repository and install:
# Create directory for Docker's GPG key
sudo install -m 0755 -d /etc/apt/keyrings
# Download and add Docker's GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package list and install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Verify Docker installation
docker --version
docker compose versionConfigure Docker user (optional, to run without sudo):
sudo usermod -aG docker $USER
newgrp docker
docker run hello-worldClone Dify Repository
Download Dify and prepare for deployment:
# Clone the Dify repository
git clone https://github.com/langgenius/dify.git
# Navigate to the docker directory
cd dify/docker
# Copy the example environment file
cp .env.example .envConfigure Environment
Edit the .env file to customize your installation:
nano .envKey configurations to update:
# Application settings
APP_NAME=Dify
APP_ENV=production
APP_DEBUG=false
APP_URL=http://your-domain.com # Replace with your domain or IP
# Database settings
DB_DATABASE=dify
DB_USERNAME=postgres
DB_PASSWORD=your-secure-password # Change this!
# Redis settings
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=your-redis-password # Change this!
# Security settings
SECRET_KEY=your-secret-key # Generate a secure random string
# Storage settings
STORAGE_TYPE=local
STORAGE_LOCAL_PATH=storage
# Vector database (Weaviate)
VECTOR_STORE=weaviate
WEAVIATE_ENDPOINT=http://weaviate:8080Generate secure passwords:
# Generate random passwords
openssl rand -base64 32 # For DB_PASSWORD
openssl rand -base64 32 # For REDIS_PASSWORD
openssl rand -base64 64 # For SECRET_KEYDeploy Dify Services
Launch all Dify services using Docker Compose:
# Start Dify services
docker compose up -d
# Check that all containers are running
docker compose psDeployed Services
- • API: Core backend service
- • Worker: Background task processor
- • Web: Frontend interface
- • Database: PostgreSQL for application data
- • Redis: Caching and session storage
- • Weaviate: Vector database for RAG
- • Nginx: Reverse proxy and load balancer
Monitor the deployment:
# View logs for all services
docker compose logs -f
# Check specific service logs
docker compose logs api
docker compose logs web
docker compose logs dbConfigure Firewall
Secure your installation with proper firewall rules:
# Install and configure UFW firewall
sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Allow SSH
sudo ufw allow 22/tcp
# Allow HTTP and HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Enable firewall
sudo ufw --force enable
# Check status
sudo ufw statusNginx Reverse Proxy
Install and configure Nginx:
# Install Nginx
sudo apt install -y nginx
# Create Nginx configuration
sudo nano /etc/nginx/sites-available/difyAdd this configuration:
server {
listen 80;
server_name your-domain.com;
client_max_body_size 100M;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_request_buffering off;
}
location /api {
proxy_pass http://localhost:5001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Enable the configuration:
# Enable the site
sudo ln -s /etc/nginx/sites-available/dify /etc/nginx/sites-enabled/
# Remove default site
sudo rm /etc/nginx/sites-enabled/default
# Test configuration
sudo nginx -t
# Restart Nginx
sudo systemctl restart nginxSSL Certificate
Secure your Dify installation with Let's Encrypt:
# Install Certbot
sudo apt install -y certbot python3-certbot-nginx
# Obtain SSL certificate
sudo certbot --nginx -d your-domain.com -d www.your-domain.com
# Test automatic renewal
sudo certbot renew --dry-runAccess & Initialize Dify
Navigate to your Dify installation to begin setup:
Initial Setup Steps
- Open your browser and visit http://your-domain.com or http://your-vps-ip
- You'll see the Dify installation page
- Create your admin account with secure credentials
- Configure model providers (add API keys for OpenAI, Anthropic, etc.)
- Upload knowledge base documents for RAG applications
- Create your first AI app using the visual interface
Performance Optimization
Optimize Docker settings:
sudo nano /etc/docker/daemon.jsonAdd these optimizations:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"storage-driver": "overlay2",
"default-ulimits": {
"memlock": {
"hard": -1,
"soft": -1
},
"nofile": {
"hard": 65536,
"soft": 65536
}
}
}sudo systemctl restart dockerSystem optimizations:
# Increase file descriptor limits
echo "* soft nofile 65536" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 65536" | sudo tee -a /etc/security/limits.conf
# Optimize virtual memory
echo "vm.max_map_count=262144" | sudo tee -a /etc/sysctl.conf
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
# Apply changes
sudo sysctl -pMaintenance & Backups
Keep Dify updated:
# Navigate to Dify directory
cd dify/docker
# Stop services
docker compose down
# Pull latest changes
git pull origin main
# Update Docker images
docker compose pull
# Start services
docker compose up -dCreate a backup script:
sudo nano /root/backup-dify.sh#!/bin/bash
BACKUP_DIR="/root/dify-backups"
DATE=$(date +%Y%m%d_%H%M%S)
# Create backup directory
mkdir -p $BACKUP_DIR
# Backup database
docker compose exec -T db pg_dump -U postgres dify > $BACKUP_DIR/db_$DATE.sql
# Backup storage
tar -czf $BACKUP_DIR/storage_$DATE.tar.gz ./volumes/app/storage/
# Backup configuration
cp .env $BACKUP_DIR/.env_$DATE
# Keep only last 7 days
find $BACKUP_DIR -name "*.sql" -mtime +7 -delete
find $BACKUP_DIR -name "*.tar.gz" -mtime +7 -delete
echo "Backup completed: $DATE"# Make executable
chmod +x /root/backup-dify.sh
# Schedule daily backups
(crontab -l 2>/dev/null; echo "0 2 * * * /root/backup-dify.sh") | crontab -Troubleshooting
Containers not starting
# Check container status
docker compose ps
# View logs
docker compose logs -f
# Restart services
docker compose restartDatabase connection errors
# Check database logs
docker compose logs db
# Verify database credentials in .env
cat .env | grep DB_
# Restart database
docker compose restart dbCannot access web interface
# Check nginx status
sudo systemctl status nginx
# View nginx logs
sudo tail -f /var/log/nginx/error.log
# Test nginx configuration
sudo nginx -tOut of memory errors
Consider upgrading to a VPS with more RAM (8GB recommended for heavy workloads).
# Check memory usage
free -h
# Monitor Docker resource usage
docker statsReady to Build AI Applications?
Get started with a RamNode Cloud VPS optimized for Dify. Our 4GB Standard plan provides the perfect balance of performance and affordability for your AI platform.
