Not every Dify deployment needs load balancers, managed databases and a Terraform repository. If you are running Dify for yourself or a small team, the cheapest setup that is still honest to call “production” is a single EC2 instance running the official Docker Compose stack — hardened, backed up, and served over HTTPS. This guide walks through that setup and is clear about where its limits are.
I run Dify on AWS for client work in Japan, and I still keep a personal instance on EC2. It costs less per month than the managed architecture in my ECS Fargate guide, and for a handful of users the difference in reliability does not matter. What does matter is doing the small number of things that separate a demo from a deployment: replacing the default secrets, closing the network, and having backups you have actually tested.
A note on versions: this guide follows the official Dify documentation as of December 2026. The Compose deployment requires Docker Compose 2.35.0 or later, and the documented minimum hardware is 2 CPU cores and 4 GiB of RAM. Dify releases move quickly, so check the current documentation and the files under docker/ in the Dify repository before you deploy.
What you will have at the end

- One EC2 instance running the full Dify Compose stack (API, worker, web, PostgreSQL, Redis, vector store and the rest) behind a reverse proxy
- HTTPS on your own domain, with only ports 80 and 443 reachable from the internet
- Every bundled default secret replaced with a real one
- Automated backups: EBS snapshots for the instance and a scheduled database dump you can restore from
- A clear picture of what this setup cannot do, and when to move off it
Who this setup is for

This is the right shape for a personal instance, a small internal tool for a team of two to ten people, or a serious evaluation you expect to run for months. Traffic is modest, uptime expectations are human (“fix it tomorrow” is acceptable), and one person operates everything. In that world, a single well-kept instance beats a distributed system you have to babysit.
It is the wrong shape for a client-facing service with an uptime promise, for heavy document indexing, or for anything where an hour of downtime becomes a business problem. A single instance is a single point of failure, and no amount of hardening changes that. If that is your situation, skip ahead to the ECS Fargate architecture instead of growing this one past its limits.
Choosing the instance

Start from the documented minimum: at least 2 cores and 4 GiB of RAM. That minimum does run Dify, but the Compose stack starts well over a dozen containers, and document indexing plus a code sandbox compete for the same memory. In practice, treat 4 GiB as the floor for a trial and 8 GiB as the comfortable size for an instance you intend to keep.
For storage, a general-purpose SSD volume in the 30–50 GB range is a sensible starting point for the operating system, the Docker images and the bundled databases. Knowledge-base documents and uploads live on this disk in the default Compose configuration, so size it for your content, not just the software. If the knowledge base grows large, that growth is one of the signals to move storage — and eventually the whole deployment — to managed services.
On cost: a single instance of this size, with its storage, is an estimated USD 25–50 per month in the Tokyo region as of December 2026. Treat that as a planning estimate, not a quote — check the current EC2 pricing page for your instance type and region before you budget. Model API usage, if you call Bedrock or another provider, is billed separately and can exceed the instance cost for a busy deployment.
Locking down the network

The security group is your firewall, and the rule is simple: the internet may reach ports 80 and 443, and nothing else. Port 80 exists so the reverse proxy can redirect to HTTPS and answer certificate challenges; all real traffic belongs on 443. The database, Redis and every other container port stay closed — the Compose stack’s data services have no reason to be reachable from outside the host.
SSH needs the same discipline. Restrict port 22 to your own IP address, or better, avoid opening it at all and use AWS Systems Manager Session Manager to reach the instance through the console or CLI. Either way, “open to the world for convenience” is how small instances get compromised, and a Dify host holds your model provider keys.
One more network note: Dify’s first-run setup screen creates the initial administrator account, and until you complete it, anyone who can reach the address can claim it. Do the initial setup immediately after the stack starts, before you announce the address to anyone — or keep the security group closed to your IP only until the admin account exists.
Installing Dify with Docker Compose

The deployment itself follows the official quick start. Install Docker Engine and Docker Compose (2.35.0 or later) on the instance, clone the Dify repository, and work in its docker/ directory. Before starting anything, copy the example environment file to .env and work through the secrets checklist in the next section — the order matters, because the database initialises with the password it finds on first boot.
Start the stack with docker compose up -d, using the default profile unless you know you need the optional services. Then open the install page at http://your-domain/install (through the proxy, this becomes your HTTPS address) and create the administrator account. After that, sign in and confirm the console loads, the worker is running, and a small test workflow executes.
Two operational habits are worth forming on day one. First, pin your deployment: note the Dify version you installed, and upgrade deliberately rather than pulling the latest images by reflex. Second, keep a copy of your .env file somewhere safe and private — losing it means losing the values that encrypt and sign parts of your deployment’s data.
HTTPS with a reverse proxy

Dify’s Compose stack serves plain HTTP through its bundled nginx on port 80 by default (the EXPOSE_NGINX_PORT setting controls the published port). For a real deployment, put a reverse proxy in front that terminates TLS: a common pattern on a single instance is a lightweight proxy with automatic Let’s Encrypt certificates, or nginx configured with certificates you manage. The proxy listens on 443, forwards to the Compose nginx, and redirects port 80 traffic to HTTPS.
Whichever proxy you choose, set Dify’s console, service API and web app base URLs to your HTTPS domain afterwards. If you skip this, share links, file URLs and OAuth callbacks will quietly point at the wrong address or scheme. Test one full round trip — sign in, upload a file, open a published app link — before calling the setup done.
The secrets checklist

The Compose files ship with development credentials so the demo starts in one command, and every one of them is public knowledge. Replacing all of them is the single most important step in this guide. The official documentation lists what to change in docker/.env before other people can reach the deployment:
- Database and Redis: set DB_PASSWORD and REDIS_PASSWORD to strong, unique values.
- Code sandbox: set SANDBOX_API_KEY and CODE_EXECUTION_API_KEY to the same strong secret.
- Weaviate: set WEAVIATE_API_KEY to a strong secret listed in WEAVIATE_AUTHENTICATION_APIKEY_ALLOWED_KEYS, and set WEAVIATE_AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=false so the vector store requires authentication.
- Plugin daemon: set PLUGIN_DAEMON_KEY and PLUGIN_DIFY_INNER_API_KEY to separate strong values.
- Agent tokens: replace the bundled agent API token and generate the agent server secret key in its required format, keeping the local sandbox auth token generated at startup.
Apply changes by restarting the stack so the new values take effect. One exception deserves care: the database password. Once the database has been initialised, change the password on the database server first and only then update DB_PASSWORD to match — changing only the .env file locks the application out of its own database.
Also note the default stack’s quiet strength: it publishes no host ports for the database, Redis, the sandbox or Weaviate. Keep it that way. Restrict access to those services on the private network too, not just at the security group.
Backups that actually exist

Two layers cover a single-instance deployment. EBS snapshots — scheduled automatically with AWS Backup or a lifecycle policy — capture the whole volume, including Docker’s data. Separately, schedule a regular pg_dump of the Dify database to a file that is copied off the instance, for example to an S3 bucket, so a lost instance does not take the only copy with it.
The rule from my managed-architecture guide applies unchanged: a backup you have never restored is a hope, not a backup. In the first month, restore a snapshot to a throwaway instance (or at least restore the database dump into a scratch container) and confirm Dify starts and your apps are present. The twenty minutes that takes is the cheapest insurance in this entire setup.
The honest limits

Availability is the obvious one: patching, a failed upgrade or an instance problem means downtime, because there is nothing else to serve traffic. Scaling is the second: when indexing or concurrent users outgrow the box, your only move is a bigger instance and a maintenance window. Neither is a defect — they are the price of the cheapest tier, and they are acceptable exactly as long as the audience is small and forgiving.
Upgrades are manual work here, too. Read the target release’s upgrade guide first, and run every Compose command with the same project name and options as your original deployment, so the named volumes stay attached and the same configuration is loaded. A full walkthrough of upgrading safely is coming in a companion article (in preparation); the short version is: back up, read the guide, then upgrade — never in another order.
When to graduate to ECS Fargate

Move when any of these become true: the instance serves people outside your own team, downtime starts costing money or trust, indexing load makes the console sluggish, or you are avoiding upgrades because they feel risky. Those are signs the operational work has outgrown the savings. My guide to self-hosting Dify on AWS with Terraform builds the managed version — ECS Fargate for the services, Aurora PostgreSQL and ElastiCache for the data, S3 for files — and most of what you learned here transfers: the secrets discipline, the settings that matter, and the backup habit.
Summary

A single EC2 instance running the official Compose stack is the cheapest Dify deployment worth calling production: 2 cores and 4 GiB at minimum, a security group that exposes only 80 and 443, a reverse proxy for HTTPS, every default secret replaced, and snapshots plus database dumps you have test-restored. It will not scale and it will not survive its own host — and for a personal instance or a small team, it does not need to. When it does, the Fargate architecture is the next step, not a bigger box.
Coming next in this series (in preparation): What Dify on AWS Actually Costs, a three-architecture comparison; and a guide to connecting Dify to Amazon Bedrock as your model provider.
