Deploy Dify
Self-hosted Dify: build AI chatbots, agents and RAG workflows visually.
plugin-daemon
Just deployed
/app/storage
Just deployed
Redis
Just deployed
/data
ssrf-proxy
Just deployed
worker-beat
Just deployed
Just deployed
Just deployed
Just deployed
Just deployed
api-websocket
Just deployed
Just deployed
/var/lib/postgresql/data
difystorage
Bucket
Just deployed
Deploy and Host Dify on Railway

Dify is the visual platform for building LLM apps, with 159,000+ GitHub stars: chatbots, AI agents, RAG knowledge bases and multi-step workflows, all designed on a drag-and-drop canvas and published as web apps or APIs. This template deploys the complete self-hosted Dify stack on Railway, with the API, workers, plugin daemon, code sandbox, Postgres with pgvector, Redis and object storage wired together over the private network. Dify Cloud's Professional plan is $59/month for 3 members and 5,000 message credits. Self-hosted Dify has no credit cap or member limit, and you only pay for hosting and the model APIs you choose.
What This Template Deploys
| Service | Purpose |
|---|---|
| proxy | Caddy on port 8080, the single public HTTPS entry point. Routes the console, APIs, WebSockets, files and plugin webhooks. |
| web | Dify's Next.js frontend: the studio, app builder and published web apps. |
| api | The Dify API on Dify 1.16.1. Runs database migrations at boot. |
| worker and worker-beat | Celery workers for document indexing, workflows and scheduled jobs. |
| api-websocket | Real-time collaboration, so several people can edit the same workflow canvas. |
| plugin-daemon | Installs and runs Dify plugins (model providers, tools), stored on a volume at /app/storage. |
| sandbox | Isolated runtime for code nodes in workflows, with egress through the SSRF proxy. |
| ssrf-proxy | Squid egress guard that blocks requests to private addresses. |
| Postgres | Postgres 18 for app data, plus pgvector as the vector store for knowledge bases. |
| Redis | Cache, Celery broker and event bus, persisted to its volume. |
| Bucket | A Railway Bucket (difystorage) for uploaded files and documents, reached over S3. |
That's 11 services in one project, matching Dify's own docker-compose setup. All secrets are generated at deploy time and every connection uses a Railway reference variable.
About Hosting Dify
Dify is a lot of moving parts. A production install needs the API, two kinds of background workers, a frontend, a plugin runtime, a sandbox for user code, a vector store, a cache, object storage and a reverse proxy that serves all of it on one origin. Self-hosting usually means a VPS with docker-compose, a mounted nginx config, TLS certificates and a lot of RAM.
On Railway, every piece runs as its own service you can scale, restart or update independently. HTTPS is automatic and all internal traffic stays on the private network. Postgres, Redis and the plugin daemon keep their data on volumes, and uploads live in a managed bucket. The proxy replaces Dify's nginx config, so the browser sees one domain for the console, APIs and published apps.
Secure first-run setup. The admin setup screen asks for INIT_PASSWORD, which is generated for you on the api service. Copy it from the Variables tab before you open the site. Public sign-up is off, so only people you invite can join.
Typical cost: ~$20–40/month on Railway for the full stack, plus your model provider's API usage. Railway's Pro plan ($20/month) is the better fit for this many services. Dify Cloud Team costs $159/month.
Deploy Dify in Under 10 Minutes
- Click Deploy on Railway. All 11 services and the bucket start, and the API runs migrations (about 5–8 minutes).
- Open the
apiservice's Variables and copyINIT_PASSWORD. - Visit your
proxydomain, enter the init password, and create the admin account. - Under Settings, Model Provider, install a provider plugin (OpenAI, Anthropic, Gemini, Ollama, OpenRouter and more) and add your API key.
- Create a chatbot, agent or workflow, upload documents to a knowledge base, and publish it as a web app or API.
No docker-compose. No nginx config. No message-credit caps.
Common Use Cases
- Self-hosted Dify Cloud alternative. The same studio with no credit cap, member limit or app limit.
- RAG chatbots over your documents. Upload PDFs, docs and web pages into knowledge bases and answer questions with citations.
- AI agents with tools. Give agents web search, APIs and custom tools from the plugin marketplace.
- Internal AI workflows. Chain LLM calls, code nodes, HTTP requests and conditions into repeatable pipelines.
- Customer support assistants. Embed a published chat app on your site or call it through the API.
- LLM app backend. Use Dify's service API as the backend for your own product, with logs and annotations built in.
- Model comparison. Swap providers per app to compare cost and quality without rewriting prompts.
Configuration
| Variable | Required | Description |
|---|---|---|
INIT_PASSWORD | 🔐 Auto-generated | Unlocks the first-run admin setup screen. Find it on the api service. |
SECRET_KEY | 🔐 Auto-generated | Signs sessions and encrypts stored provider keys. Never change it after setup. |
ALLOW_REGISTER, ALLOW_CREATE_WORKSPACE | ✅ Set | false. Users join by invitation only. |
CONSOLE_WEB_URL, APP_WEB_URL, SERVICE_API_URL, FILES_URL | ✅ Auto-injected | All point at the proxy's public domain. Update them for a custom domain. |
STORAGE_TYPE, S3_* | ✅ Auto-injected | s3, with endpoint and keys from the Railway Bucket. |
VECTOR_STORE | ✅ Set | pgvector, using the bundled Postgres. |
SERVER_WORKER_AMOUNT | Optional | 2 Gunicorn workers on the API. Raise it with more RAM. |
FORCE_VERIFYING_SIGNATURE | ✅ Set | true, so only signed marketplace plugins install. |
ENABLE_NETWORK (sandbox) | Optional | true. Code nodes reach the internet through the SSRF proxy only. |
Using a custom domain? Add it to the proxy service, then update the *_URL variables on api, worker and web so links, file URLs and webhooks use it.
Dify on Railway vs. Alternatives
| Dify on Railway | Dify Cloud | n8n Cloud | Langflow (self-hosted) | |
|---|---|---|---|---|
| Monthly cost | ~$20–40 usage | $59 Professional, $159 Team | From €20 (annual) | Hosting only |
| Self-hosted | ✅ Yes | ❌ No | ❌ No | ✅ Yes |
| Usage limits | ✅ None | ❌ 5,000 credits on Professional | ❌ 2,500 executions on Starter | ✅ None |
| Visual LLM workflow builder | ✅ Yes | ✅ Yes | ⚠️ General automation | ✅ Yes |
| Built-in RAG knowledge base | ✅ Yes, pgvector | ✅ Yes | ⚠️ Via nodes | ⚠️ Via components |
| Publish as web app or API | ✅ Both | ✅ Both | ⚠️ Webhooks | ✅ API |
| License | ⚠️ Modified Apache 2.0 (source-available) | ❌ Proprietary hosting | ⚠️ Sustainable Use | ✅ MIT |
Dependencies for Dify Hosting
- Railway account. Pro ($20/month) is recommended for an 11-service stack.
- An API key from at least one model provider, or a self-hosted model endpoint.
- Optional: a custom domain for published apps.
Deployment Dependencies
- Dify on GitHub: source code and releases
- Dify Documentation: self-hosting, apps and workflows
- Dify Plugin Marketplace: model providers and tools
- Railway Volumes Documentation: persistence
Implementation Details
The API, workers and websocket service share the langgenius/dify-api image in different modes. The proxy is a Caddy translation of Dify's nginx config, needed because Railway routes by domain rather than path. Code nodes run in dify-sandbox and all outbound traffic from the API and sandbox goes through Squid, which blocks private network ranges.
Images are pinned to Dify 1.16.1. To upgrade, change every dify-api and dify-web image to the same new tag and redeploy. Back up Postgres first.
Frequently Asked Questions
What is Dify, and why self-host it? Dify is a visual builder for LLM apps, agents, RAG and workflows. Self-hosting removes Dify Cloud's credit and member limits and keeps your prompts, documents and logs on your own infrastructure.
How much does self-hosted Dify cost compared to Dify Cloud? About $20–40/month on Railway for the full stack, plus model API usage. Dify Cloud Professional is $59/month (3 members, 5,000 credits) and Team is $159/month.
Where do I find the password for the Dify setup screen?
It's INIT_PASSWORD in the api service's Variables tab, generated at deploy time. Enter it on the setup page, then create your admin account.
Do I lose apps or knowledge bases on redeploy? No. App data and vectors are in Postgres, plugins are on the plugin-daemon volume, and uploaded files are in the Railway Bucket. Redeploys and upgrades keep all of it.
Which models can Dify use? Any provider with a Dify plugin, including OpenAI, Anthropic, Gemini, Mistral, OpenRouter and Ollama, plus OpenAI-compatible endpoints. Install them from the marketplace in Settings.
Can I run Dify as a SaaS for other companies? Not without a commercial license. Dify's license is Apache 2.0 with extra conditions: no multi-tenant service, and the frontend logo and copyright must stay. Internal and single-company use is fine.
Why Deploy and Host Dify on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Dify on Railway, you get the complete Dify stack, with workers, plugins, sandbox, vector store and storage, running on your own infrastructure with no credit caps, so your team can build and ship AI apps freely.
Template Content
plugin-daemon
langgenius/dify-plugin-daemon:0.6.3-localRedis
redis:8.2ssrf-proxy
gridalpha/dify-railwayworker-beat
langgenius/dify-api:1.16.1api-websocket
langgenius/dify-api:1.16.1difystorage
Bucket

