Your own n8n with private AI on a VPS
Hostinger + Docker + n8n + Ollama, step by step: automations and an AI model on your own server, with no cost per message.
Paying per message to an AI company adds up, and every email or customer message you send it leaves your hands. With a small server you can run n8n and an AI model side by side, for the price of the server alone.
This is the exact setup we run at Somosbanana: a Hostinger KVM 2, Docker Compose, n8n behind Caddy with automatic HTTPS, and Ollama with qwen2.5:3b. The 12-minute video goes through it on our real server; here is every command, ready to copy.
Watch the full video on YouTube
What you need
- A VPS: Hostinger KVM 2 (2 vCPU, 8 GB RAM, about $8.79/month paying 24 months; renews at $14.99). KVM 1 is enough for n8n alone
- A domain, or a subdomain like n8n.yourdomain.com
- A terminal: Terminal on Mac, PowerShell or Windows Terminal on Windows
- About an hour. Everything else (Docker, n8n, Ollama, Caddy) is free and open source
1. Choose and set up the VPS
Go to hostinger.com/vps-hosting. The AI model has to fit in RAM with room for n8n, so RAM is what matters: KVM 1 (4 GB) for n8n alone or a 1.5b model, KVM 2 (8 GB) for n8n plus a 3b model, KVM 4 (16 GB) for 7b, KVM 8 (32 GB) for 14b. Check the renewal price under each plan.
When you check out, pick plain Ubuntu (latest LTS), the data center closest to your customers, and a long root password saved in a password manager, or better, an SSH key. Hostinger also sells a VPS with n8n preinstalled (hostinger.com/self-hosted-n8n): fine as a shortcut, but for the AI you still need the RAM of a KVM 2.
When it's ready, open your VPS in the Hostinger panel: the overview shows its IP and the SSH command.
2. Connect and switch on the firewall
SSH opens a terminal on the server. Type yes the first time, then the password (nothing shows while you type). Update the system, then lock every port except SSH (22) and the web (80 and 443). Ollama's port, 11434, stays closed: only n8n talks to it, inside the server.
While preparing the video we found our own firewall was off. Check yours with ufw status.
ssh root@YOUR_IP
apt update && apt upgrade -y
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
3. Install Docker
An image is the recipe of a program, a container is that program running in its own box, and a volume is the folder where it keeps its data, so updates never erase anything. Install Docker with its official script and check both versions answer.
curl -fsSL https://get.docker.com | sh
docker --version && docker compose version
4. Point your domain
Where your domain is managed (Hostinger panel under Domains and DNS, Cloudflare or your registrar), add an A record: name n8n, value your server's IP. On Cloudflare leave the cloud grey for now so Caddy can get its certificate. After a few minutes, ping n8n.yourdomain.com should answer with your IP.
5. Generate the encryption key
This key locks every password and token you store in n8n. Copy it somewhere safe outside the server: if you lose it, n8n can't read your saved credentials. In nano, save with Ctrl+O and Enter, exit with Ctrl+X.
mkdir -p /opt/n8n && cd /opt/n8n
openssl rand -hex 32
nano docker-compose.yml
6. n8n + Ollama in one file
Paste this into docker-compose.yml with your key and domain. n8n only listens inside the server (127.0.0.1:5678) and Caddy publishes it. Ollama has no ports at all: n8n reaches it by its service name. mem_limit keeps the model from choking the server.
services:
n8n:
image: docker.n8n.io/n8nio/n8n:latest
restart: unless-stopped
ports: ["127.0.0.1:5678:5678"]
environment:
N8N_ENCRYPTION_KEY: "PASTE_YOUR_KEY"
N8N_HOST: n8n.yourdomain.com
N8N_PROTOCOL: https
WEBHOOK_URL: https://n8n.yourdomain.com/
N8N_PROXY_HOPS: "1"
GENERIC_TIMEZONE: Europe/Madrid
volumes: [n8n:/home/node/.n8n]
depends_on: [ollama]
ollama:
image: ollama/ollama:latest
restart: unless-stopped
mem_limit: 4g
environment:
OLLAMA_NUM_PARALLEL: "1"
OLLAMA_MAX_LOADED_MODELS: "1"
volumes: [ollama:/root/.ollama]
volumes:
n8n:
ollama:
7. Start everything
up -d starts both containers in the background (the first time it downloads the images). ps shows they're running, logs shows what each one says if something fails.
docker compose up -d
docker compose ps
docker compose logs -f n8n
8. HTTPS with Caddy
Caddy receives visits to your domain with HTTPS and passes them to n8n: a reverse proxy. It asks Let's Encrypt for a free certificate and renews it on its own. Then open https://n8n.yourdomain.com and create the owner account. On the left you'll use Workflows, Credentials and Executions.
apt install -y caddy
nano /etc/caddy/Caddyfile
# Caddyfile
n8n.yourdomain.com {
reverse_proxy 127.0.0.1:5678
}
systemctl reload caddy
9. Download the AI model
The b in the name is billions of parameters: smarter, but more RAM. qwen2.5:3b weighs 1.9 GB and runs well on a KVM 2: good in English and Spanish, can use tools, fast on a normal CPU. The first answer can take a minute while it loads into memory; after that ours answers in about 7 seconds. All models: ollama.com/library.
docker compose exec ollama ollama pull qwen2.5:3b
docker compose exec ollama ollama run qwen2.5:3b "Translate to Spanish: good morning"
10. Connect n8n to Ollama
In n8n create an Ollama credential with base URL http://ollama:11434. Not localhost: inside Docker that would be n8n itself; ollama is the service name and Docker resolves it. Then use the Ollama nodes, or an HTTP Request node with POST http://ollama:11434/api/chat, which is what our email workflow does: new email (IMAP) → check it's a reply → look up the contact → the model classifies it (interested, not now, unsubscribe) → Telegram alert, CRM row and, if needed, an unsubscribe confirmation.
11. Keep it safe
Only ports 22, 80 and 443 open. Update every few weeks with one line (your data stays in the volumes). Take a snapshot from the backups section of your VPS in the Hostinger panel before any big change. Keep the encryption key and root password in a password manager, outside the server.
docker compose pull && docker compose up -d
One server, your own n8n and your own AI, for the price of the VPS. Start with one workflow that saves you an hour a week, and grow from there.
Tu propio n8n con IA privada en un VPS. Hostinger + Docker + n8n + Ollama, paso a paso: automatizaciones y un modelo de IA en tu propio servidor, sin coste por mensaje.