---
title: "Self-host Dify on your own VPS: multi-service LLM workflows, RAG and private model gateways"
description: "Deploy Dify on your own Linux server with PostgreSQL, Redis/Valkey and isolated sandbox services over Zenavo private networking, wire it to LiteLLM, New API or SearXNG, and keep knowledge base data on your own machine."
date: 2026-11-16
language: en
url: https://zenavo.app/blog/self-host-dify
---

# Self-host Dify on your own VPS: multi-service LLM workflows, RAG and private model gateways

Building an internal RAG assistant or multi-step LLM workflow usually means gluing together prompt templates, document chunking, vector search, tool calls and API logs. [Dify](https://github.com/langgenius/dify) packages all of that into a visual workflow studio and an API backend you can self-host. Running it on your own VPS keeps uploaded documents, embeddings and execution logs on your own disk without cloud workspace limits.

This guide covers how Dify's services fit together on Zenavo, how to wire it to a self-hosted model gateway or search tool over `.zenavo.internal`, and what to check when bringing it up. Your server and Zenavo are billed separately.

## 1. Server sizing and architecture

Dify is a multi-service stack rather than a single container. For a smooth setup with document indexing and concurrent workflow runs, [connect a Linux server](https://docs.zenavo.app/servers/add-a-server) with at least **4 GB of memory** (8 GB if you also run a vector database and local embedding workloads on the same host).

Inside a single Zenavo project, every service resolves the others over the [project private network](https://docs.zenavo.app/networking/private) without exposing internal ports to the internet:

| Component | Role in the stack | Persistent storage / notes |
|---|---|---|
| `postgresql` | Primary relational store (plus `pgvector` if used as your vector backend) | Persistent volume at `/var/lib/postgresql/data`; schedule backups in **Backup & Restore** |
| `redis` / `valkey` | Celery task queue, cache and rate-limit state | Persistent volume if you want queued tasks to survive restarts |
| `dify-api` & `dify-worker` | `langgenius/dify-api` (`MODE=api` and `MODE=worker`) | Shared `SECRET_KEY`, database URL, Redis URL, and `/app/api/storage` volume for uploaded files |
| `dify-web` | `langgenius/dify-web` Next.js console | Points `CONSOLE_API_URL` and `APP_API_URL` at your public HTTPS domain |
| `dify-sandbox` | `langgenius/dify-sandbox` isolated runner for Code nodes | Reachable only from `dify-api` / `dify-worker` over `.zenavo.internal` |
| `nginx` (or proxy) | Routes `/console/api`, `/api`, `/v1`, `/files` → `dify-api:5001` and `/` → `dify-web:3000` | The only service that needs a public domain bound on port `80` |

Check the [Zenavo Templates gallery](https://zenavo.app/templates) first for one-step AI stacks, or import/create the services in one project on your server.

## 2. Critical environment variables

Most Dify startup and login issues come down to mismatched URLs or missing secrets between `dify-api`, `dify-worker` and `dify-web`:

1. **`SECRET_KEY`**: generate one strong random string and set the **exact same value** on both `dify-api` and `dify-worker`. Dify uses it to encrypt stored model provider keys and workspace tokens.
2. **Public URLs on `dify-web` and `dify-api`**: once you bind your custom domain (for example `dify.example.com`) under [Domains & HTTPS](https://docs.zenavo.app/networking/domains), set `CONSOLE_API_URL`, `CONSOLE_WEB_URL`, `SERVICE_API_URL`, `APP_API_URL` and `APP_WEB_URL` to `https://dify.example.com`.
3. **Private database & Redis URLs**: point `DB_HOST` at `postgresql.zenavo.internal` and `REDIS_HOST` at `redis.zenavo.internal` (or `valkey.zenavo.internal`). Neither database needs a public port.
4. **Vector store**: if you use PostgreSQL with `pgvector` (`VECTOR_STORE=pgvector`), you can keep both relational data and embeddings in one managed PostgreSQL service that is easy to snapshot via [Backups & Restore](https://docs.zenavo.app/operations/backups).

> **Keep `SECRET_KEY` safe**: back up `SECRET_KEY` in a password manager (such as self-hosted [Vaultwarden](https://zenavo.app/blog/self-host-vaultwarden)). Changing `SECRET_KEY` later makes previously saved model credentials in PostgreSQL unreadable.

## 3. Wire Dify to your own model gateway and search engine

Instead of pasting raw OpenAI or Anthropic keys directly into Dify, you can connect Dify to another self-hosted service in the same Zenavo project over `.zenavo.internal`:

- **Model gateway ([LiteLLM](https://zenavo.app/blog/self-host-litellm), [New API](https://zenavo.app/blog/self-host-new-api), or [Magpie](https://zenavo.app/blog/self-host-magpie))**: in Dify's **Settings → Model Provider → OpenAI-API-compatible**, set the API Endpoint URL to `http://litellm.zenavo.internal:4000/v1` (or your New API / Magpie internal service address) and paste a virtual key or token. All Dify traffic stays on your server's private network with centralized budgets and spend logs.
- **Private web search ([SearXNG](https://zenavo.app/blog/self-host-searxng))**: enable JSON output in SearXNG and point Dify's built-in SearXNG tool at `http://searxng.zenavo.internal:8080` so your agents can ground answers in live web results without paid search API quotas.
- **General workflow automation ([n8n](https://zenavo.app/blog/self-host-n8n))**: let Dify handle LLM chains, knowledge retrieval and prompt versioning, then trigger n8n webhooks for CRM syncs, Slack alerts or scheduled batch jobs.

## 4. Initialize the admin account and verify workers

1. Open `https://dify.example.com/install` right after the services turn `Running` and create the initial admin account.
2. Create a simple **Chatbot** or **Workflow** app and upload a small Markdown or PDF file into **Knowledge** to verify that `dify-worker` processes the indexing queue cleanly.
3. If a Knowledge upload stays stuck in `Indexing`, open the built-in [Zenavo Agent](https://docs.zenavo.app/zenavo-agent) on the right edge of the console and ask it to inspect `dify-worker` and `redis` logs—or debug directly from your terminal with [Claude Code and `zenavo-mcp`](https://zenavo.app/blog/claude-code-deploy-debug).

## FAQ

**Why does Dify show a blank page or fail to log in after setting a domain?**
Check that `CONSOLE_API_URL` and `APP_API_URL` on `dify-web` match your `https://` domain (without a trailing slash) and that your reverse proxy forwards `/console/api` and `/api` to `dify-api` on port `5001`.

**Why do uploaded Knowledge documents stay in `Queuing` or `Indexing` forever?**
`dify-worker` is either not running, pointing at a different Redis/Valkey instance than `dify-api`, or missing the shared `/app/api/storage` volume if `dify-api` and `dify-worker` run as separate services.

**Should I use Dify or n8n?**
Use **Dify** when the core problem is prompt orchestration, RAG knowledge bases, model comparison and publishing a chat/completion API. Use **[n8n](https://zenavo.app/blog/self-host-n8n)** when you need 400+ SaaS integrations, cron schedules and webhook glue—or pair them together over `.zenavo.internal`.

**Can I migrate an existing Dify setup from Zeabur to Zenavo?**
Yes. Export your project template YAML from Zeabur and import it in Zenavo (see [Migrate from Zeabur](https://zenavo.app/blog/migrate-from-zeabur)), then restore your PostgreSQL dump via **Backup & Restore** (see [Migrate PostgreSQL from Zeabur](https://zenavo.app/blog/migrate-zeabur-postgresql)) and keep the original `SECRET_KEY`.

[Connect a Linux server](https://docs.zenavo.app/servers/add-a-server) or browse the [Zenavo Templates gallery](https://zenavo.app/templates) to run your AI workflows and knowledge bases on infrastructure you control.
