Self-Host n8n on a VPS (Docker Compose + HTTPS)
Deploy n8n on your own VPS with Docker Compose and Caddy for automatic HTTPS, then set up updates, backups and security.
Video chapters
- 00:00Intro
- 00:43n8n Cloud or self-host?
- 01:45What you need before we start
- 02:26Step 1: Prepare the server
- 03:23Step 2: Point your domain at the server
- 04:17Step 3: The Docker Compose file
- 05:26Step 4: Caddyfile and encryption key
- 06:19Step 5: The .env file, then start
- 07:30Updates and backups
- 09:01Security checklist
- 10:05Your n8n, live on your own server
In this episode we move n8n off the laptop and onto a server we control. By the end, n8n runs 24/7 at https://n8n.yourdomain.com, with automatic HTTPS, a persistent data volume, and a simple update and backup routine.
What you need
- A VPS with Ubuntu (2 GB RAM to start, 4 GB is comfortable)
- A domain or subdomain you control
- SSH access to the server
- About 30 minutes
n8n Cloud or self-host?
First, should you self-host at all? There are two honest options.
n8n Cloud is the easy one. There's nothing to install or maintain, and n8n handles updates and uptime. You pay a monthly plan, and that's it.
Self-hosting means n8n runs on a server you control. Your workflows and data stay with you, and you're not limited by a plan's execution count.
The trade-off is that you are now the operations team. Updates, backups and security are your job. That's what most of this video is about, so you can do it properly from day one.
The cost is usually small. A basic VPS with two to four gigabytes of RAM is enough for most personal and small business workloads.
And there's a bonus. Setting this up teaches you Docker, DNS and HTTPS, which are core skills for any automation or cloud engineer. If you're building workflows for clients, being able to host them is a real advantage.
Quick reference
- n8n Cloud: Zero setup, managed for you, monthly plan
- Self-host: Your server, your data, no limit on executions
- You own the work: Updates, backups and security are your job
- Cost: A small VPS often costs less than a coffee a week
- Skill bonus: Docker, DNS and HTTPS: real DevOps practice
What you need before we start
Here's what you need before we start.
A VPS from any provider, running Ubuntu. Two gigabytes of RAM is enough to start, and four gives you comfortable room for bigger workflows and AI nodes.
A domain you control. You don't need a new one. A subdomain like n8n dot your domain dot com works perfectly, and it's what we'll use today.
SSH access, so you can log in to the server from your terminal.
Docker, which we'll install in a single command in the next step.
And around thirty minutes. Most of that is waiting for downloads and for DNS to update. The actual typing is short.
Quick reference
- A VPS: Ubuntu, 2 GB RAM to start, 4 GB is comfortable
- A domain: Or a subdomain, like n8n.yourdomain.com
- SSH access: Log in from your terminal as root or a sudo user
- Docker: We install it in one command, next step
- 30 minutes: Most of it is waiting for DNS and downloads
Step 1 · Prepare the server
Step one: prepare the server. Open your terminal and log in with SSH, using the IP address your provider gave you.
Update the system packages first. On a fresh server this can take a minute.
Next, install Docker. Docker's official convenience script installs the Docker engine and the compose plugin together.
Check that it worked by running docker compose version. If you see a version number, you're ready.
Now the firewall. We only want three ports open: SSH for you, and ports eighty and four four three for the web. Notice that n8n's own port, fifty-six seventy-eight, is not on this list. Nobody should reach n8n directly. All traffic will go through the HTTPS proxy.
One important warning. Always allow SSH before you enable the firewall. If you enable it first, you can lock yourself out of your own server.
Quick reference
ssh root@YOUR_SERVER_IP apt update && apt upgrade -y curl -fsSL https://get.docker.com | sh docker compose version ufw allow OpenSSH && ufw allow 80 && ufw allow 443 ufw enable
Step 2 · Point your domain at the server
Step two: point your domain at the server. Open the DNS settings wherever your domain is managed. That's usually your registrar, or a service like Cloudflare.
Add an A record. The name is n8n, and the value is your server's IP address.
This creates the address n8n dot your domain dot com, and tells the internet that it lives on your server. If you use Cloudflare, set this record to DNS only, the grey cloud, while we set things up, so the certificate step works smoothly.
DNS changes are usually quick, but they can take a few minutes, sometimes longer.
Test it by pinging the new address. When it replies with your server's IP, you're ready for the next step. Don't skip this check. HTTPS certificates can only be issued once the domain points at the right server.
Quick reference
- Open your domain's DNS settings
- Add an A record: name “n8n”, value = server IP
- Wait a few minutes, then test it
- ping n8n.yourdomain.com → shows your IP
DNS RECORD
Type: A
Name: n8n
Value: 203.0.113.10 (your server IP)
TTL: Auto / 300
Result: n8n.yourdomain.com
→ 203.0.113.10Step 3 · The Docker Compose file
Step three: the Docker Compose file. This one file describes everything we run.
Create a folder called n8n in your home directory, and move into it.
Inside, create a file called docker compose dot yml, and add two services.
The first is n8n itself, using the official image. Restart unless stopped means it comes back automatically after a crash or a server reboot. Its settings come from a dot env file, which we'll create in a moment. And its data folder is stored in a named volume, n8n data. That volume holds your workflows, your credentials, and your execution history.
The second service is Caddy, a web server that handles HTTPS for us. It's the only container with open ports, eighty and four four three. It reads a small config file called the Caddyfile, and it stores its certificates in its own volume.
At the bottom, we declare both volumes. Volumes are the reason your data survives restarts and updates. Containers can be deleted and recreated at any time, but the volumes stay.
Quick reference
- mkdir ~/n8n && cd ~/n8n
- Create docker-compose.yml
- n8n: the app, data in a volume
- caddy: HTTPS proxy, ports 80 + 443
- Volumes survive restarts + updates
docker-compose.yml
services:
n8n:
image: docker.n8n.io/n8nio/n8n
restart: unless-stopped
env_file: .env
volumes:
- n8n_data:/home/node/.n8n
caddy:
image: caddy:2
restart: unless-stopped
ports: ["80:80", "443:443"]
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
volumes: {n8n_data: {}, caddy_data: {}}Step 4 · Caddyfile and encryption key
Step four: the Caddyfile. This is the whole configuration, just three lines.
The first line is your domain. When Caddy sees a real domain name here, it automatically requests an HTTPS certificate for it, and renews it before it expires. You never touch certificates yourself.
Inside, reverse proxy n8n, port fifty-six seventy-eight. Because both containers are in the same compose project, Caddy can reach n8n simply by its service name.
Next, generate an encryption key with openssl. n8n uses this key to encrypt every credential you save, like your Gemini key or your Telegram token.
Copy that key somewhere safe, like a password manager. If you ever move to a new server, you'll need the same key, or your saved credentials can't be decrypted.
Quick reference
n8n.yourdomain.com {
reverse_proxy n8n:5678
}
openssl rand -hex 32Step 5 · The .env file, then start
Step five: the dot env file, and then we start everything.
Create a file called dot env, next to the compose file. N8N host is your domain. The protocol is HTTPS. The webhook URL is your full public address, and this is the setting that fixes the localhost webhook problem from the Telegram episode. Set your time zone, so schedules run at the time you expect. And paste in your encryption key.
Now start everything with docker compose up, dash d. The dash d runs it in the background, so it keeps running after you log out.
Watch Caddy's logs for a moment. Within a minute, you should see a message that the certificate was obtained. If it fails, the cause is almost always DNS not pointing at the server yet, or port eighty being blocked.
Open your domain in the browser. You'll see a padlock, and the n8n setup screen.
Create the owner account with a strong password. This account controls everything, so treat it like a server password. Then import or rebuild your workflows from the earlier episodes, and they'll run here, around the clock.
Quick reference
- docker compose up -d
- docker compose logs -f caddy → certificate obtained
- Open https://n8n.yourdomain.com
- Create the owner account with a strong password
.env
N8N_HOST=n8n.yourdomain.com N8N_PROTOCOL=https WEBHOOK_URL=https://n8n.yourdomain.com/ GENERIC_TIMEZONE=Europe/London N8N_ENCRYPTION_KEY=<your key>
Updates and backups
A server you don't maintain is a server waiting to break. So here's a simple routine.
To update n8n, go into the n8n folder, pull the latest images, and run up dash d again. Compose recreates only the containers that changed, and your data stays in the volume.
For backups, the most important thing is the n8n data volume.
This command starts a tiny temporary container, mounts the volume, and packs everything into a single compressed file in your current folder. The volume name starts with n8n underscore, because compose prefixes volumes with the project folder's name. You can confirm the exact name with docker volume ls.
Then copy that file, together with your dot env file, off the server. A backup that lives on the same server as the data doesn't protect you if the server is lost. Many people also export their important workflows to Git, which gives you version history for free.
And before any big version jump, read the n8n release notes and take a backup first. It takes one minute, and it can save you a whole day.
Once you're comfortable with the backup command, put it in a small script, and schedule it with cron to run every night. Add a line that copies the file to cloud storage, like an S3 bucket or Google Drive, and delete old backups after a couple of weeks. That's a professional backup setup, in about ten lines.
Quick reference
docker compose pull && docker compose up -d
docker run --rm -v n8n_n8n_data:/data -v $PWD:/backup \
alpine tar czf /backup/n8n-backup.tgz -C /data .Security checklist
Before we finish, a short security checklist. Your n8n holds API keys and access to your accounts, so it's worth five minutes.
One. The firewall only allows SSH, eighty and four four three. Never publish port fifty-six seventy-eight directly.
Two. Use SSH keys to log in, and once that works, disable password login. This stops most automated attacks on your server.
Three. Use a long, unique password for the n8n owner account, and turn on two-factor authentication in your n8n user settings if your version offers it.
Four. Stay updated. Apply Ubuntu security updates, and keep n8n reasonably current.
And five. Keep backups off the server, and test a restore at least once, so you know it actually works.
None of these steps is difficult on its own. The value comes from doing all of them every time you set up a server. Save this checklist in your notes, and run through it for every client server you deploy.
Quick reference
- Firewall: Only 22, 80 and 443. Never expose 5678
- SSH keys: Log in with keys, then disable password login
- Strong owner login: Long password, plus two-factor if available
- Stay updated: Regular updates for Ubuntu, Docker and n8n
- Off-server backups: Volume backup + .env, stored somewhere else
Your n8n, live on your own server
Let's recap the setup. Traffic from the internet, whether it's a person, a webhook, or Telegram, arrives at Caddy over HTTPS. Caddy passes it to n8n inside Docker, which is never exposed directly. And everything important lives in the n8n data volume, which you back up off the server.
This pattern, DNS, an HTTPS proxy, the app, and a persistent volume, is how a huge number of real applications are deployed. You'll see it again and again, including in our cloud engineering course.
In the next episode, we use this server for what it's best at: webhooks and APIs, so any app, website or service can talk to your workflows. The notes, with every file from this video, are linked in the description.
Quick reference
Internet → Caddy → n8n → n8n_data
DNS → HTTPS proxy → app → persistent volume
Practice
- Point a second subdomain at the same server and serve a static page from Caddy.
- Run the backup command, then restore it into a fresh test volume.
- Move your Telegram bot from Episode 3 to this server and check it replies.
Next episode
Episode 5: Webhooks and APIs, connecting any app or service to n8n.
Key takeaways
- Docker Compose runs n8n plus Caddy, which gets and renews HTTPS certificates for you
- Workflows and credentials live in the n8n_data volume: back it up off the server
- Keep N8N_ENCRYPTION_KEY safe, or saved credentials can't be decrypted on a new server
- Open only ports 22, 80 and 443, and never expose n8n's port 5678 directly