Running Ollama with Open WebUI on your own Linux VPS gives you a private AI chat interface and a local model API with flat monthly costs and zero third-party data sharing. This guide deploys Ollama 0.40.18 and Open WebUI v0.13.4 on an Ubuntu 24.04 VPS using Docker Compose and Caddy for automatic HTTPS — keeping port 11434 isolated on the private Docker network and locking public signups right after creating your admin account.
Every image tag, environment variable and healthcheck below matches the upstream v0.40.18 Ollama release (envconfig/config.go and Dockerfile) and v0.13.4 Open WebUI release (docker-compose.yaml, backend/open_webui/env.py, config.py and Dockerfile).
Before deploying, set realistic expectations: on a standard Linux VPS (vCPUs and RAM, no dedicated GPU), Ollama runs inference on CPU using system memory bandwidth.
That works well for:
A CPU-only VPS is not built for dozens of concurrent chat users or 32B/70B models. The table below summarizes practical 4-bit quantized (Q4_K_M, Ollama's default) model sizes by VPS memory:
| VPS tier (CPU) | Comfortable models ( Q4 ) |
Recommended workload |
|---|---|---|
| 4 GB RAM · 2 vCPU | 1B to 3B models ( llama3.2:3b ) |
Quick tests, embeddings ( nomic-embed-text ) and light triage |
| 8 GB RAM · 4 vCPU | 3B to 4B models ( qwen3:4b ,gemma3:4b ) |
Daily single-user chat in Open WebUI with safe memory headroom |
| 12 GB RAM · 6 vCPU | 7B to 8B models ( qwen2.5:7b ,llama3.1:8b ) |
Production Open WebUI, RAG and n8n workflows without OOM kills |
| 24 GB RAM · 8 vCPU | 14B models or 8B with larger context windows | Small team usage, longer context and other stacks on the host |
Memory rule of thumb. A 4-bit 8B model needs roughly 5 GB to 6 GB of RAM just for weights, plus KV context cache, the Open WebUI backend (~600 MB to 1 GB) and the OS. On an 8 GB VPS, an 8B model runs right on the edge; 12 GB of RAM leaves genuine headroom so the Linux OOM killer does not terminate Ollama mid-generation.
The most common mistake when self-hosting Ollama on a VPS is publishing port 11434 on 0.0.0.0. Ollama has no built-in authentication: anyone scanning your IP can pull arbitrary models, fill your disk and peg your CPU at 100%.
In this setup, only Caddy binds ports 80 and 443 on the host. Open WebUI (8080) and Ollama ( 11434) communicate exclusively over the private Docker Compose network:
Four details prevent the usual first-day pitfalls:
WEBUI_SECRET_KEY is required in Open WebUI v0.13.4: docker-compose.yaml leaves it blank, but env.py explicitly aborts startup when WEBUI_AUTH=True and ollama list: ollama/ollama:0.40.18 Ubuntu 24.04 image does not bundle curl or wget. Running 11434 is ready.OLLAMA_MAX_LOADED_MODELS=1 and OLLAMA_NUM_PARALLEL=1: ENABLE_SIGNUP=true stays on only while you create the first account (automatically promoted to Admin), then switches to false. v2.20+), ideally ufw allowing only 22/tcp, 80/tcp and 443 (TCP/UDP).A record pointing to the VPS IPv4 (ia.example.com in the examples below).
If Docker and ufw are not configured yet, start with the server setup in How to install n8n with Docker on a VPS.
.env
Create the stack directory and generate a strong random WEBUI_SECRET_KEY:
mkdir -p ~/ollama-webui && cd ~/ollama-webui
openssl rand -hex 32
Create .env with your domain, email and generated secret key:
OLLAMA_VERSION=0.40.18
OPEN_WEBUI_VERSION=v0.13.4
CADDY_VERSION=2.11
WEBUI_DOMAIN=ia.example.com
ACME_EMAIL=[you@example.com](mailto:you@example.com)
WEBUI_URL=[https://ia.example.com](https://ia.example.com)
WEBUI_SECRET_KEY=paste-your-64-char-hex-key-here
ENABLE_SIGNUP=true
DEFAULT_USER_ROLE=pending
OLLAMA_KEEP_ALIVE=5m
OLLAMA_MAX_LOADED_MODELS=1
OLLAMA_NUM_PARALLEL=1
OLLAMA_CONTEXT_LENGTH=4096
Lock down file permissions on .env:
chmod 600 .env
What each Ollama guard in .env controls:
OLLAMA_KEEP_ALIVE=5m: OLLAMA_CONTEXT_LENGTH=4096: 8192 on 12 GB or 24 GB tiers if needed).Caddyfile
Caddy provisions and renews the TLS certificate automatically and proxies both streamed chat responses and WebSockets to Open WebUI:
{
email {$ACME_EMAIL}
}
{$WEBUI_DOMAIN} {
encode zstd gzip
reverse_proxy open-webui:8080
}
Create docker-compose.yml #
This Compose file pins tested tags, keeps ollama and open-webui off the host network interface and waits for Ollama to become healthy before starting the UI:
services:
caddy:
image: caddy:${CADDY_VERSION}
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
environment:
- WEBUI_DOMAIN=${WEBUI_DOMAIN}
- ACME_EMAIL=${ACME_EMAIL}
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
open-webui:
condition: service_healthy
ollama:
image: ollama/ollama:${OLLAMA_VERSION}
restart: unless-stopped
environment:
- OLLAMA_KEEP_ALIVE=${OLLAMA_KEEP_ALIVE}
- OLLAMA_MAX_LOADED_MODELS=${OLLAMA_MAX_LOADED_MODELS}
- OLLAMA_NUM_PARALLEL=${OLLAMA_NUM_PARALLEL}
- OLLAMA_CONTEXT_LENGTH=${OLLAMA_CONTEXT_LENGTH}
volumes:
- ollama_data:/root/.ollama
healthcheck:
test: ["CMD", "ollama", "list"]
interval: 15s
timeout: 5s
retries: 10
start_period: 15s
open-webui:
image: ghcr.io/open-webui/open-webui:${OPEN_WEBUI_VERSION}
restart: unless-stopped
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- WEBUI_SECRET_KEY=${WEBUI_SECRET_KEY}
- WEBUI_URL=${WEBUI_URL}
- ENABLE_SIGNUP=${ENABLE_SIGNUP}
- DEFAULT_USER_ROLE=${DEFAULT_USER_ROLE}
volumes:
- open_webui_data:/app/backend/data
depends_on:
ollama:
condition: service_healthy
volumes:
caddy_data:
caddy_config:
ollama_data:
open_webui_data:
No host ports: on Ollama or Open WebUI. The ghcr.io/open-webui/open-webui:v0.13.4 image already ships a built-in HEALTHCHECK against http://localhost:8080/health, so Caddy waits until the backend is ready. Never add "11434:11434" to ollama, because Docker bypasses ufw — see Docker port still open with ufw.
Validate the Compose configuration and bring the stack up:
cd ~/ollama-webui
sudo docker compose config --quiet
sudo docker compose up -d
sudo docker compose ps
The first Open WebUI startup takes 1 to 2 minutes while it initializes its SQLite database and assets inside /app/backend/data. Wait until both ollama and open-webui show Up (healthy).
Now pull a model that fits your VPS memory directly inside the Ollama container. For a fast smoke test on any 4 GB+ server, start with llama3.2:3b; on 12 GB+ servers, pull a 7B/8B model such as qwen2.5:7b:
sudo docker compose exec ollama ollama pull llama3.2:3b
On a 12 GB+ VPS:
sudo docker compose exec ollama ollama pull qwen2.5:7b
Verify the downloaded model and run a quick CLI check before opening the browser:
sudo docker compose exec ollama ollama list
sudo docker compose exec ollama ollama run llama3.2:3b "Reply in one short sentence: is the server working?"
Check the HTTPS health endpoint through Caddy:
curl -fsS https://ia.example.com/health
You should get {"status":true}. Next:
https://ia.example.com in your browser and register the first user — Open WebUI automatically grants ENABLE_SIGNUP=false in open-webui:
sed -i 's/^ENABLE_SIGNUP=true$/ENABLE_SIGNUP=false/' .env
sudo docker compose up -d open-webui
Verify that no internal port leaked onto public host interfaces:
sudo ss -tulpn | grep -E ':(80|443|8080|11434)\b'
Only ports 80 and 443 should be listening publicly.
To call your local models from workflows or another server without opening port 11434:
http://ollama:11434. https://ia.example.com/api/chat/completions with Authorization: Bearer <your-key>. Every external request stays encrypted and authenticated through Caddy and Open WebUI.
You do not need to back up ollama_data (multi-gigabyte model weights can be re-downloaded with ollama pull). Back up .env (which holds WEBUI_SECRET_KEY) and open_webui_data (users, chats, prompts and RAG collections):
cd ~/ollama-webui
(umask 077 && cp .env open-webui-env-$(date +%F))
sudo docker compose stop open-webui
sudo docker run --rm -v ollama-webui_open_webui_data:/data:ro -v "$PWD":/backup alpine tar czf /backup/open-webui-data-$(date +%F).tar.gz -C /data .
sudo docker compose start open-webui
Copy both files off the VPS regularly.
OLLAMA_VERSION or OPEN_WEBUI_VERSION in
cd ~/ollama-webui
sudo docker compose pull
sudo docker compose up -d
sudo docker compose ps
sudo docker compose logs --tail=50 open-webui. On WEBUI_AUTH is enabled.OLLAMA_BASE_URL=http://ollama:11434 matches the Compose service name and run sudo docker compose exec ollama ollama list to confirm at least one model is pulled.OOMKilled: sudo docker inspect --format '{{.State.OOMKilled}}' ollama-webui-ollama-1, lower OLLAMA_CONTEXT_LENGTH to 2048 or switch to a smaller model (3b on 4–8 GB; 7b/ 8b on 12 GB+).OLLAMA_KEEP_ALIVE=30m or -1, while keeping Originally published at https://nuvits.net/en/blog/install-ollama-open-webui-linux-vps