Self-host Dify

Open-source platform for building and running LLM applications, with visual workflows, agents, knowledge bases and an API for the apps it publishes. Run your own Dify on an always-on EnvHaven workspace by asking its coding agent: one request installs it, puts it on an HTTPS address and locks it down. What the agent takes care of, and the manual route.

Updated November 23, 2026

Running your own Dify usually means a list of server chores: a machine that stays on, Docker or a runtime, a reverse proxy with certificates, a domain, and the settings that make Dify behave behind all of it. On an EnvHaven workspace you skip the list. You ask the coding agent, and it does the work while you watch.

Just ask your agent

Open a Plus workspace (Dify runs in Docker, which Plus and Pro include), tap Launch to start any coding agent (Claude Code, Codex, OpenCode or another), and ask it:

Set up Dify on this workspace and give me the link. Follow https://envhaven.com/self-host/dify.md

Then open the link it sends and create your Dify account straight away, before anyone else finds the address. That is the whole request: the address in it is this page’s Markdown copy, and the agent follows the instructions for it further down, with every setting Dify’s docs require.

Or keep it private with Tailscale

The preview URL puts Dify on the public internet, which suits something other people need to reach. For an app only you and your household use, your tailnet is the better home: Tailscale gives Dify an HTTPS address that only your own devices, signed in to your Tailscale account, can open. Save a Tailscale auth key in the workspace’s Vars pane as TS_AUTHKEY, and ask the agent:

Set up Dify on my tailnet instead of the preview URL. Follow https://envhaven.com/self-host/dify.md and https://envhaven.com/guides/self-host-privately-with-tailscale.md
  • A Tailscale container runs beside Dify, so it keeps its private address through workspace restarts and updates, and every app you set up this way gets an address of its own.
  • Anything other services have to reach, such as a webhook, still needs a public address. Keep self-hosted apps private with Tailscale covers both, and what Tailscale’s free plan includes.
At a glance
What it isAI chat, models and agent tools
LicenseDify Open Source License
Runs asDocker (langgenius/dify-api)
Memoryat least 4 GiB (docs)
Plan that fitsPlus or larger
Web port80
Documentationdocs.dify.ai/en/self-host/deploy/quick-start/docker-compose

What your agent takes care of

  • Installing it. Dify runs from the official image, langgenius/dify-api, with its data in folders under ~/apps/dify.
  • Putting it on an HTTPS address. The workspace’s preview URL serves it, and your own domain can too.
  • Locking it down first. What Dify’s docs say to set before it faces the internet, below.
  • Telling you what to back up: docker/volumes/ (PostgreSQL at volumes/db/data, Redis, Weaviate, app storage at volumes/app/storage, plugin_daemon, sandbox), docker/volumes/app/storage/.dify_secret_key (generated SECRET_KEY), docker/.env and the local service .env files under docker/envs/ and named volumes of local_sandbox (/home/dify and /workspace) (docs).

The settings it needs behind a proxy

  • CONSOLE_API_URL, CONSOLE_WEB_URL, SERVICE_API_URL, APP_API_URL, APP_WEB_URL, FILES_URL (in docker/envs/core-services/urls.env): Public base URLs, empty by default. With everything at one address and email, OAuth or Human Input in use, set them all to the full public address. (docs)
  • URL format: Write each URL with its scheme and port; leave off the API path suffixes. (docs)
  • CONSOLE_API_URL and CONSOLE_WEB_URL with https: Secure cookies need both URLs to start with https://. (docs)
  • CONSOLE_CORS_ALLOW_ORIGINS and WEB_API_CORS_ALLOW_ORIGINS: Allowed cross-origin callers for the console API and the Web API; both default to *, and the console value falls back to CONSOLE_WEB_URL when unset. (docs)
  • COOKIE_DOMAIN and NEXT_PUBLIC_COOKIE_DOMAIN: Needed only when the console and API sit on different subdomains of one parent domain. (docs)
  • NEXT_PUBLIC_SOCKET_URL: WebSocket address the browser uses for real-time collaboration; the default ws://localhost only works on the server itself, so set it to wss://your-host and restart. (docs)
  • WebSocket proxying on /socket.io/: A proxy in front of Dify must forward Upgrade and Connection headers on /socket.io/; the bundled nginx already does. (docs)
  • NGINX_HTTPS_ENABLED: Lets the bundled nginx terminate TLS with a certificate and key in ./nginx/ssl/; leave it false when a tunnel or proxy terminates TLS. (docs)
  • Trusted proxy for visitor IPs (RESPECT_XFORWARD_HEADERS_ENABLED and the Nginx trust setup): Behind Cloudflare or another proxy, every visitor shares the proxy’s address and its sign-in email limits until the bundled Nginx is told which proxy to trust. (docs)

Before it faces the internet

  • The first visitor to /install creates the administrator account. Set INIT_PASSWORD so the install page asks for it before an account can be created on an exposed server. (docs)
  • Before others can reach the deployment, configure HTTPS and replace the bundled development credentials: DB_PASSWORD, REDIS_PASSWORD, SANDBOX_API_KEY and CODE_EXECUTION_API_KEY, WEAVIATE_API_KEY, PLUGIN_DAEMON_KEY and PLUGIN_DIFY_INNER_API_KEY, and the DIFY_AGENT_* tokens. (docs)
  • Set DIFY_AGENT_LOCAL_SANDBOX_AUTH_TOKEN (openssl rand -hex 32) in .env before the first start; the agent backend and its sandbox need it. (docs)
  • Keep SECRET_KEY stable (or keep the generated .dify_secret_key in persistent storage); changing it invalidates tokens and signed file URLs. (docs)
  • The plugin daemon publishes its debugging port 5003 on the host by default, unlike the database, Redis, sandbox and Weaviate; firewall it on a public server. (docs)

Things to ask next

Everything after the install is one more sentence to the agent. Some that come up:

  • “Connect it to the API keys in my Vars pane, and make Claude the default model.”
  • “Add a second user account for my partner, without admin rights.”
  • “Move Dify to app.example.com.” Add the domain on the dashboard’s Domains page with a CNAME to domains.envhaven.app, and the agent changes Dify’s address settings to match.
  • “Update Dify to the latest release.” It pulls the new image and recreates the container, data kept.

Instructions for the agent

The agent reads these from the page’s Markdown copy. They also work pasted on their own, if you would rather give them in your own words.

Set up Dify on this workspace and serve it at my preview URL.
- Use Docker Compose with the official image, langgenius/dify-api, starting from the docs' compose file: https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml. If `docker compose` is missing, install the Compose plugin into ~/.docker/cli-plugins first.
- The docs' setup includes: postgres (db_postgres profile; MySQL is an alternative); redis; weaviate (default vector store; other bundled vector stores are selectable); nginx; worker and worker_beat (Celery, same image as api); sandbox and local_sandbox (code execution); plugin_daemon; agent_backend; ssrf_proxy and agent_ssrf_proxy (Squid); api_websocket (collaboration profile); init_permissions (one-off task).
- Keep the compose file in ~/apps/dify and all of its data in folders there (bind mounts, not named volumes), with restart: unless-stopped on every service.
- This server has no firewall, so publish no port on its public IP, and drop host networking and privileged mode from the docs' compose file. Docker runs on the host: connect this workspace to the compose network and relay my preview URL's port to Dify's port 80.
- The preview URL terminates HTTPS in front of Dify: serve plain HTTP on its port, and trust the forwarded headers the relay passes on.
- Set what "The settings it needs behind a proxy" lists on https://envhaven.com/self-host/dify.md for the preview URL, as Dify's docs describe for running behind a proxy; skip any that apply only when Dify serves HTTPS itself.
- Before the preview URL serves it, apply what "Before it faces the internet" lists on https://envhaven.com/self-host/dify.md.
- When it answers at the preview URL, send me the link and tell me what to back up.
- If I asked for my tailnet instead of the preview URL, set Dify up the same way but follow https://envhaven.com/guides/self-host-privately-with-tailscale.md for the network: no preview URL, no relay.

What to know

  • In Docker, Dify’s containers keep running when the workspace restarts or updates. The relay from the preview URL is a process in the workspace, so after a restart or an update, ask the agent to restore it.
  • Document uploads default to 15 MB and images to 10 MB, and the bundled nginx caps request bodies at 100M, which already matches Cloudflare’s 100 MB request limit; raising limits above 100 MB would not help behind Cloudflare. (docs)
  • All upload limits are also gated by the proxy body size. (docs)
  • The stack needs Docker Compose 2.35.0 or later. (docs)
  • Account invitations, password resets and login codes are sent by email; without a mail provider the invitation page shows a link to copy by hand. (docs)
  • Real-time workflow collaboration uses a separate api_websocket container and WebSocket traffic, so the tunnel or proxy must pass WebSockets. (docs)
  • A workspace has one preview URL and one custom domain, both serving the same port, so it puts one app on a public address at a time.

Without a workspace

The manual route, on a server you run:

  1. Rent a Linux VPS, secure SSH, and create a user for the app.
  2. Install Docker and write a compose file from the official image.
  3. Put a reverse proxy in front (Caddy, nginx or Traefik), get certificates, and point a domain at the server.
  4. Set the proxy settings listed above for that domain, and pass WebSocket upgrades through the proxy if the app uses them.
  5. Keep the firewall closed except for the proxy, and schedule backups and updates.

Dify’s own documentation covers each step for its install methods.

Sources

Facts about Dify come from its own documentation, checked on 2026-11-23: