AI agents & automation
How to install n8n on a VPS with Docker and free SSL
Self-host n8n on your own VPS with Docker Compose, a free Let's Encrypt certificate and correct webhook URLs. Tested setup, real RAM numbers and backups.

On this page
n8n is the automation tool most people reach for when they want AI agents that actually do things: answer messages, update a CRM, summarise emails, call APIs. Running it on your own VPS means no per-execution pricing, your data stays on your server, and you can connect it to anything the server can reach.
This guide sets up n8n with Docker Compose behind Traefik, with a free Let's Encrypt certificate and correct webhook URLs. Every file below was validated with docker compose config, and the n8n image was run and measured before publishing.
What you need
- A VPS with at least 2 GB of RAM. Idle, n8n 2.47.7 used about 740 MB in our test. AI agent workflows, code nodes and parallel executions add to that, so 4 GB is the comfortable size if the server does anything else.
- A domain or subdomain you can point at the server, for example
n8n.example.com. - SSH access as root or a user with
sudo.
If you don't have a server yet, our guide to what a VPS is explains what to look for. Hostinger's KVM plans are a common choice for this; the KVM 2 plan we run our own projects on has 2 vCPUs, 8 GB of RAM and 100 GB of disk, which leaves plenty of room for n8n plus other containers.
Step 1: Point a subdomain at the server
In your DNS settings, create an A record:
| Name | Type | Value |
|---|---|---|
n8n | A | Your VPS IPv4 address |
Wait until it resolves before continuing, otherwise the certificate request in step 5 fails:
dig +short n8n.example.com
Step 2: Install Docker
Many VPS providers offer an image with Docker preinstalled (Hostinger has an "Ubuntu 24.04 with Docker and Traefik" template). On a clean Ubuntu server, use Docker's official convenience script:
curl -fsSL https://get.docker.com | sudo sh
docker compose version
Step 3: Create the project folder and settings
mkdir -p ~/n8n && cd ~/n8n
openssl rand -hex 32
Copy the random string from the last command. It becomes your encryption key: n8n uses it to encrypt the credentials you save (API keys, passwords). Lose it and those credentials can't be decrypted, so store it somewhere safe.
Create a file named .env:
DOMAIN_NAME=example.com
SUBDOMAIN=n8n
GENERIC_TIMEZONE=Asia/Riyadh
SSL_EMAIL=you@example.com
N8N_ENCRYPTION_KEY=paste-the-random-string-here
Use your own timezone (for example Africa/Cairo or Asia/Dubai) so scheduled workflows run at the times you expect.
Step 4: Create the Compose file
Create compose.yaml in the same folder:
services:
traefik:
image: traefik:v3
restart: unless-stopped
command:
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.websecure.address=:443
- --certificatesresolvers.le.acme.tlschallenge=true
- --certificatesresolvers.le.acme.email=${SSL_EMAIL}
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
ports:
- "80:80"
- "443:443"
volumes:
- traefik_data:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
n8n:
image: n8nio/n8n:2.47.7
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
- N8N_PORT=5678
- N8N_PROTOCOL=https
- N8N_PROXY_HOPS=1
- N8N_WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- NODE_ENV=production
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
- TZ=${GENERIC_TIMEZONE}
volumes:
- n8n_data:/home/node/.n8n
labels:
- traefik.enable=true
- traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
- traefik.http.routers.n8n.entrypoints=websecure
- traefik.http.routers.n8n.tls.certresolver=le
- traefik.http.services.n8n.loadbalancer.server.port=5678
volumes:
n8n_data:
traefik_data:
A few choices worth understanding:
- The n8n version is pinned (
2.47.7) instead oflatest, so an update only happens when you decide. - Port 5678 is bound to
127.0.0.1: n8n is reachable from the internet only through Traefik and HTTPS, never directly. N8N_WEBHOOK_URLmakes webhook URLs in the editor use your real domain. On n8n versions before 2.30 the variable is calledWEBHOOK_URL.N8N_PROXY_HOPS=1tells n8n it sits behind one reverse proxy, so it sees real visitor IPs.
Step 5: Start n8n
docker compose up -d
docker compose logs -f n8n
When the log shows Editor is now accessible via, open https://n8n.example.com. The first request triggers the Let's Encrypt certificate, which takes a few seconds. Create the owner account straight away; until you do, anyone who finds the URL could claim it.
To check the service from the server itself:
curl -s http://127.0.0.1:5678/healthz
# {"status":"ok"}
Step 6: Back up the right things
Two things matter: the n8n_data volume (workflows, credentials, execution history) and your encryption key in .env.
cd ~/n8n
docker compose stop n8n
docker run --rm -v n8n_n8n_data:/data -v "$PWD":/backup alpine \
tar czf /backup/n8n-data-$(date +%F).tgz -C /data .
docker compose start n8n
Docker prefixes volume names with the folder name, so the volume is n8n_n8n_data when the folder is ~/n8n. Check yours with docker volume ls. Copy the archive and .env off the server; a backup on the same disk isn't a backup.
Updating n8n
Read the release notes, change the version in compose.yaml, then:
docker compose pull n8n
docker compose up -d n8n
Take a backup first. Database migrations run automatically on start and can't be undone by switching the image back.
Security checklist
- Create the owner account immediately and turn on two-factor authentication in your user settings.
- Keep port 5678 bound to
127.0.0.1as above; only 80 and 443 should be open to the internet. - Treat your encryption key like a password: it unlocks every credential stored in n8n.
- Update regularly. n8n connects to many services, so security fixes matter.
- Store API keys in n8n credentials, not hard-coded inside workflow nodes.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Webhook URLs show localhost:5678 | Webhook URL not set | Set N8N_WEBHOOK_URL (or WEBHOOK_URL before 2.30) and recreate the container |
| Browser warns about the certificate | DNS not pointing at the server yet, or port 443 blocked | Check dig, open ports 80/443 in the provider's firewall, then restart Traefik |
| Login fails over plain HTTP | n8n uses secure cookies | Always use the https:// address |
| Container restarts repeatedly | Not enough memory | Check docker stats; move to a plan with more RAM |
Next steps
With n8n running, you can build AI agent workflows that call a language model, use tools and remember context. If you're deciding between keeping things on shared hosting and moving to a server, our shared hosting vs VPS comparison covers the trade-offs.
Hostinger
Available worldwide
Budget-friendly web, WordPress and VPS hosting with its own hPanel dashboard and data centers on several continents.
1AZMI19Frequently asked questions
How much RAM does n8n need?
In our test, n8n 2.47.7 used about 740 MB of RAM while idle with no workflows. Plan for at least 2 GB on the server, and 4 GB or more if you run AI agent workflows, many executions in parallel or other containers next to it.
Can I install n8n on shared hosting?
Usually not. n8n is a long-running Node.js service, and most shared hosting plans don't allow Docker or background processes. A small VPS is the practical minimum.
Is self-hosted n8n free?
The self-hosted Community Edition doesn't charge per workflow or execution; you pay for the server. It is distributed under n8n's Sustainable Use License, so read it before offering n8n to clients as a hosted service.
Sources & references
Related reading
VPS & cloud
What is a VPS, and when do you actually need one?
A virtual private server gives you guaranteed resources and full control, along with full responsibility. Here is how it works and the signs you are ready for one.
2 min read
Web hosting
Shared hosting vs VPS: what's the real difference?
Shared hosting is simple and cheap; a VPS gives you guaranteed resources and full control. A clear comparison of cost, performance, security, effort and when to move.
2 min read
AI agents & automation
Best VPS for n8n and AI agents: how much server you actually need
How much RAM and CPU n8n, OpenClaw, Hermes Agent and Ollama really need, which VPS plan size fits each, and what to check before you pick a provider.
2 min read